Hybrid_Providers_Facebook::getUserContacts PHP Method

getUserContacts() public method

public getUserContacts ( )
    function getUserContacts()
    {
        $apiCall = '?fields=link,name';
        $returnedContacts = [];
        $pagedList = true;
        while ($pagedList) {
            try {
                $response = $this->api->get('/me/friends' . $apiCall, $this->token('access_token'));
                $response = $response->getDecodedBody();
            } catch (FacebookSDKException $e) {
                throw new Hybrid_Exception("User contacts request failed! {$this->providerId} returned an error {$e->getMessage()}", 0, $e);
            }
            // Prepare the next call if paging links have been returned
            if (array_key_exists('paging', $response) && array_key_exists('next', $response['paging'])) {
                $pagedList = true;
                $next_page = explode('friends', $response['paging']['next']);
                $apiCall = $next_page[1];
            } else {
                $pagedList = false;
            }
            // Add the new page contacts
            $returnedContacts = array_merge($returnedContacts, $response['data']);
        }
        $contacts = [];
        foreach ($returnedContacts as $item) {
            $uc = new Hybrid_User_Contact();
            $uc->identifier = array_key_exists("id", $item) ? $item["id"] : "";
            $uc->displayName = array_key_exists("name", $item) ? $item["name"] : "";
            $uc->profileURL = array_key_exists("link", $item) ? $item["link"] : "https://www.facebook.com/profile.php?id=" . $uc->identifier;
            $uc->photoURL = "https://graph.facebook.com/" . $uc->identifier . "/picture?width=150&height=150";
            $contacts[] = $uc;
        }
        return $contacts;
    }