2016-04-08 10 views
0

Google APIを初めて使用しており、People APIを使用してユーザーの連絡先をすべて取得したいと考えています。 それは動作しますが、私は、ユーザーを認証することができますし、次のように私は人々APIを呼び出す:PHPを使用してGoogle 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]配列をどのようにして読み込むのですか?

+0

[配列PHPをループ]の可能な重複(http://stackoverflow.com/questions/4414623/loop-through-an-array-php) – DaImTo

答えて

0

私はあなたと同じ問題を抱えていますが、リポジトリに明示的にv1ブランチを使用するように指定されているため、Googleの開発者サイトのドキュメントは間違っているようです。

この私がこれまで一緒にハッキングきたもので、それは不正なコードですが、うまくいけば、それはあなたを助ける:

$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/>"); 
} 
関連する問題