Skip to content

Commit

Permalink
Bug fixed on getUserContacts of Google.
Browse files Browse the repository at this point in the history
  • Loading branch information
pc committed Feb 2, 2017
1 parent f103085 commit b0dfc70
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions hybridauth/Hybrid/Providers/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,30 +197,24 @@ function getUserProfile() {
*/
function getUserContacts() {
// refresh tokens if needed

$this->refreshToken();


$contacts = array();
if (!isset($this->config['contacts_param'])) {

$this->config['contacts_param'] = array("max-results" => 500);
}

// Google Gmail and Android contacts
if (strpos($this->scope, '/m8/feeds/') !== false) {

$response = $this->api->api("https://www.google.com/m8/feeds/contacts/default/full?"
. http_build_query(array_merge(array('alt' => 'json'), $this->config['contacts_param'])));


if (!$response) {

return array();
}

if (isset($response->feed->entry)) {

foreach ($response->feed->entry as $idx => $entry) {
$uc = new Hybrid_User_Contact();
$uc->email = isset($entry->{'gd$email'}[0]->address) ? (string) $entry->{'gd$email'}[0]->address : '';
Expand Down Expand Up @@ -255,48 +249,49 @@ function getUserContacts() {
} else {
$uc->webSiteURL = '';
}

$contacts[] = $uc;
}
}
}

// Google social contacts
if (strpos($this->scope, '/auth/plus.login') !== false) {

$response = $this->api->api("https://www.googleapis.com/plus/v1/people/me/people/visible?"
. http_build_query($this->config['contacts_param']));

if (!$response) {
return array();
}

foreach ($response->items as $idx => $item) {
$uc = new Hybrid_User_Contact();
$uc->email = (property_exists($item, 'email')) ? $item->email : '';
$uc->displayName = (property_exists($item, 'displayName')) ? $item->displayName : '';
$uc->identifier = (property_exists($item, 'id')) ? $item->id : '';

$uc->description = (property_exists($item, 'objectType')) ? $item->objectType : '';
$uc->photoURL = (property_exists($item, 'image')) ? ((property_exists($item->image, 'url')) ? $item->image->url : '') : '';
$uc->profileURL = (property_exists($item, 'url')) ? $item->url : '';
$uc->webSiteURL = '';

$contacts[] = $uc;
}
}

return $contacts;
}

/**
* Add query parameters to the $url
*
* @param string $url URL
* @param array $params Parameters to add
* @return string
*/
function addUrlParam($url, array $params) {
function addUrlParam($url, array $params)

$query = parse_url($url, PHP_URL_QUERY);

// Returns the URL string with new parameters
Expand Down

0 comments on commit b0dfc70

Please sign in to comment.