我試圖使用Google People API添加和更新我的Google聯繫人。我使用Google文檔(https://developers.google.com/people/v1/getting-started)中給出的示例代碼幾乎逐字地設置了API。我得到一個錯誤以下行的代碼,它又來了逐字從文檔:錯誤「(獲取)未知參數:'personFields'」在Google People API文檔中的示例中使用
$profile = $people_service->people->get('people/me', array('personFields' => 'names,emailAddresses'));
錯誤如下:
Fatal error: Uncaught exception 'Google_Exception' with message '(get) unknown parameter: 'personFields'' in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Service/Resource.php:147 Stack trace: #0 /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/People/Resource/People.php(52): Google_Service_Resource->call('get', Array, 'Google_Service_...') #1 /home/danbak15/bakerlegalservicesmo.com/office/BLScontacts.php(36): Google_Service_People_Resource_People->get('people/me', Array) #2 {main} thrown in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Service/Resource.php on line 147
我所看到的是回答了類似的問題(Can't access my profile data when accessing google-people API )建議使用Google_Service_PeopleService類而不是文檔中所要求的Google_Service_People類。然而,當我嘗試這樣做,我得到另一個錯誤:
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ { "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "domain": "global", "reason": "unauthorized" } ], "status": "UNAUTHENTICATED" } } ' in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php:118 Stack trace: #0 /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'G in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php on line 118
在這一點上,我在全盤損失。我想使用Google通訊錄來跟蹤我的聯繫人,並希望能夠通過PHP使用Google通訊錄,以便將它們添加到我的數據庫中。任何人都可以對此有所瞭解嗎?預先感謝您的任何幫助!
更新: 我試着將頁面移動到我的計算機上的本地服務器(忘記Google將頁面重定向到我的網站),以查看是否可以從不同的服務器獲得不同的結果。不知何故,當我嘗試從我的網站上訪問腳本時,它有效地工作了大約15-30分鐘左右。然後,我得到了和以前一樣的錯誤。如果我從本地主機服務器運行該頁面,我將陷入無盡的授權重定向循環(預計Google會將我重定向到在線頁面),但這個在線頁面一段時間就會工作。
在這一點上,我無法開始猜測問題出在哪裏。這對其他人有意義嗎?
您確定您擁有最新版本的客戶端庫嗎? – paolo
我有同樣的問題,但使用Google_Service_PeopleService修復了它;我建議你專注於解決第二個錯誤。 – Isaiah
我使用的是Google API PHP Client 2.2.0版本,我認爲它是正確的版本(儘管我總是可能會誤)。在使用Google_Service_PeopleService時,我對於身份驗證憑證錯誤感到有些不知所措。我有OAuth 2憑據,在使用Google_Service_People類時工作得很好。只有當我使用Google_Service_PeopleService類時纔會引發錯誤。我應該查看或更改我的憑據中是否有某些內容? –