私はGoogle APIに問題があります。私は自分のアプリケーション内のユーザーの連絡先をすべて取得する必要がありますが、データベースにデータを格納するため、毎回すべてのデータをロードしたくありません。同期トークン例外google-api-client-service php peopleサービス
私は同期トークン機能を使用して、前回のクエリから変更されたデータのみを取得したいのです。
これは、Google APIs PHP client libraryを使用してください。
自分のコードを書きましたが、同期トークンが有効でないことを説明する例外(Google_Service_Exception)がスローされます。有効でない場合、try/catchシステムを使用してsyncTokenをリセットすることにしました。
私の問題は、自分のトークンが有効であっても、キャッチ(google_service_exception)が要求されるたびに発生します。
トークンをデータベースに保存するので、ここではAPIエクスプローラでテストしました:https://developers.google.com/people/api/rest/v1/people.connections/listと正常に動作するため、アプリケーションが正しく動作しない理由がわかりません。
ここに私のコードです:
$personFields = 'metadata,names,addresses,biographies,birthdays,emailAddresses,genders,memberships,organizations,phoneNumbers';
$user = $this->get('security.token_storage')->getToken()->getUser();
$syncToken = $user->getContactSyncToken();
$nextPagetoken = '';
$contactData = array();
$people_service = new \Google_Service_PeopleService($client);
do {
try {
$data = $people_service->people_connections->listPeopleConnections(
'people/me',
array(
'personFields' => $personFields,
'requestSyncToken' => true,
'syncToken' => $syncToken,
'pageToken' => $nextPagetoken,
)
);
}catch (\Google_Service_Exception $e){
$data = $people_service->people_connections->listPeopleConnections(
'people/me',
array(
'personFields' => $personFields,
'requestSyncToken' => true,
'syncToken' => '',
'pageToken' => $nextPagetoken,
)
);
}finally{
$syncToken = $data->getNextSyncToken();
$nextPagetoken = $data->getNextPageToken();
if (count($data->getConnections()) != 0) {
$contactData[] = $data->getConnections();
}
}
}while ($nextPagetoken !== null);
$user->setContactSyncToken($syncToken);
$this->getDoctrine()->getManager()->flush();
return $contactData;
はあなたの助けをありがとう、私の英語のため申し訳ありませんが、私はそれで非常に良好で、ネイティブとないではないです。私は問題を発見