【问题标题】:"Other Contacts" in Google API is able to retrive in PHP GooglePeopleGoogle API 中的“其他联系人”能够在 PHP Google People 中检索
【发布时间】:2020-11-14 23:19:45
【问题描述】:
当我使用https://github.com/rapidwebltd/php-google-people-api 时,我可以获得我的联系人,但不能获得其他联系人。
$refreshToken = $googleOAuth2Handler->getRefreshToken($_GET["code"]);
$people = new GooglePeople($googleOAuth2Handler);
$i=0;
// Retrieval all contacts
foreach($people->all() as $contact) {
if ($contact->names) {
echo $contact->names[0]->displayName."<br />";
}
if ($contact->phoneNumbers) {
echo $contact->phoneNumbers[0]->value."<br /><br />";
}
}
【问题讨论】:
标签:
php
gmail-api
google-contacts-api
【解决方案1】:
你好
经过一天的研究,我找到了它。这是 PHP 的代码,用于访问 google people API(其他联系人):
1- scope : $client->addScope(Google_Service_PeopleService::CONTACTS_OTHER_READONLY);
2- code :
$optParams = array(
'pageSize' => 10, //number of contact return
'readMask' => 'emailAddresses',
);
$results = $service->otherContacts->listOtherContacts($optParams);
if (count($results->getOtherContacts()) == 0) {
print "No connections found.\n";
} else {
print "Other Contact list:"; echo "<br>";
$count=0;
foreach ($results->getotherContacts() as $person) {
if (count($person->getemailAddresses()) == 0) {
print "No names found for this connection\n";
} else {
$emailAddresses = $person->getemailAddresses();
$email = $emailAddresses[$count];
$contactmail[$count]=$email->getvalue();
echo $count;echo " -"; echo $contactmail[$count];
echo "<br>";
}
}
}