【问题标题】:How to read the contact data as returned by the Google People API using PHP如何使用 PHP 读取 Google People API 返回的联系人数据
【发布时间】:2016-04-08 07:37:42
【问题描述】:

我是 google API 的新手,想使用 People API 来获取用户的所有联系人。 它有效,我可以对用户进行身份验证,然后按如下方式调用 People API:

$contacts = $peopleService->people_connections->listPeopleConnections('people/me');
  foreach ($contacts as $contactItem) {
  $this->print_r2($contactItem);
  } 

但我获得了 Google_Service_People_ListConnectionsResponse 类型的对象:

Google_Service_People_ListConnectionsResponse Object
(
[collection_key:protected] => connections
[internal_gapi_mappings:protected] => Array
    (
    )

[connectionsType:protected] => Google_Service_People_Person
[connectionsDataType:protected] => array
[nextPageToken] => 
[nextSyncToken] => CPDp4aW_KhIBMRjuEioECAAQAQ
[modelData:protected] => Array
    (
        [connections] => Array
            (
                [0] => Array
                    (
                        [resourceName] => people/c3422388075840417635
                        [etag] => AgD+4rTZF6o=
                        [metadata] => Array
                            (
                                [sources] => Array
                                    (
                                        [0] => Array
                                            (
                                                [type] => CONTACT
                                                [id] => 2fc3d288898002f63
                                                [etag] => #AgD+4rTZF6o=
                                            )

                                    )

                                [deleted] => 1
                                [objectType] => PERSON
                            )

                    )

                [1] => Array
                    (
                        [resourceName] => people/107483842333347794768
                        [etag] => btQbbIVcGJ4=
                        [metadata] => Array
                            (
                                [sources] => Array
                                    (
                                        [0] => Array
                                            (
                                                [type] => CONTACT
                                                [id] => 715e58866e51e374
                                                [etag] => #TW+s5999ANk=
                                            )

                                        [1] => Array
                                            (
                                                [type] => PROFILE
                                                [id] => 107483842299147794768
                                            )

                                    )

                                [objectType] => PERSON
                            )

                        [names] => Array
                            (
                                [0] => Array
                                    (
                                        [metadata] => Array
                                            (
                                                [primary] => 1
                                                [source] => Array
                                                    (
                                                        [type] => CONTACT
                                                        [id] => 715e50000e51e374
                                                    )

                                            )

                                        [displayName] => xxxxxxxx
                                        [familyName] => xxxxxx
                                        [givenName] => xxxxxxxxx
                                        [displayNameLastFirst] => xxxxx, xxxxx
                                    )

                                [1] => Array
                                    (
                                        [metadata] => Array
                                            (
                                                [source] => Array
                                                    (
                                                        [type] => PROFILE
                                                        [id] => *************************
                                                    )

                                            )

                                        [displayName] => xxxxxxxxxx
                                        [familyName] => xxxxx
                                        [givenName] => xxxxxxx
                                        [displayNameLastFirst] => xxxxx, xxxxxxx
                                    )

                            )

... ..... ...

我的问题有点愚蠢:我如何阅读,使用 PHP 客户端库,[modelData:protected] 数组,所以我可以得到结果 [connections]。

【问题讨论】:

标签: php google-api google-api-php-client google-people-api


【解决方案1】:

我和你有同样的问题,谷歌开发者网站上的文档似乎不正确,因为 repo 明确声明使用 v1 分支。

到目前为止,这是我一起破解的代码,它是糟糕的代码,但希望它会对你有所帮助:

$connections = $service->people_connections->listPeopleConnections('people/me', array(
    'pageSize' => 500,
    'requestMask.includeField' => 'person.names,person.phoneNumbers'
));

foreach($connections->connections as $contact){
    echo("{$contact[names][0][displayName]}<br/>");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多