PHP中的Google People API

时间:2016-08-24 14:28:35

标签: php google-api

我尝试在成功 OAuth2之后实施People API,当尝试加载人员时,错误是:

Undefined property: Google_Service_People_Resource_People::$connections

这是产生错误的行:

$people_service = new Google_Service_People($client);
$connections = $people_service->people->connections->listConnections('people/me');

按照本教程https://developers.google.com/people/v1/getting-started进行, 而这:https://developers.google.com/people/v1/requests

由于

2 个答案:

答案 0 :(得分:5)

我认为你在寻找......

$connections = $people_service->people_connections->listPeopleConnections('people/me');

答案 1 :(得分:0)

我们编写了一个可能有用的PHP Google People API库。它使通过Google People API实现对Google通讯录的访问比使用Google自己的库更容易。

链接:https://github.com/rapidwebltd/php-google-people-api

使用示例

用法

检索所有联系人

// Retrieval all contacts
foreach($people->all() as $contact) {
    echo $contact->resourceName.' - ';
    if ($contact->names) {
        echo $contact->names[0]->displayName;
    }
    echo PHP_EOL;
}

检索单个联系人

// Retrieve single contact (by resource name)
$contact = $people->get('people/c8055020007701654287');

创建新联系人

// Create new contact
$contact = new Contact($people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = 'Testy';
$contact->names[0]->familyName = 'McTest Test';
$contact->save();

更新联系人

// Update contact
$contact->names[0]->familyName = 'McTest';
$contact->save();

删除联系人

// Delete contact
$contact->delete();