簡體   English   中英

Google API PHP,服務帳戶模擬問題

[英]Google API PHP, Service Account Impersonation issues

我已經嘗試了各種方法來嘗試在此問題上取得一些進展,但我無能為力。 我正在嘗試使用服務帳戶來訪問域中用戶的日歷。 服務帳戶已設置,似乎工作正常。 據我所知,根據https://developers.google.com/identity/protocols/OAuth2ServiceAccount?hl=zh_CN#delegatingauthority啟用了域范圍委派。 在下面的代碼中,一切正常,直到我設置了模擬帳戶,並且標題中出現錯誤。 我看到過各種有關驗證模仿者用戶身份的文章,但這似乎與Google所說的不一致。 我被卡住了。

$client = new Google_Client();
$client->setSubject('email@domain.com');
$client->setAuthConfig($_SERVER['DOCUMENT_ROOT'] . '/private.json');
$client->setScopes(['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly']);

這將導致任何類型的api請求失敗,並顯示以下錯誤:

Message: {
 "error": "unauthorized_client",
 "error_description": "Unauthorized client or scope in request."
}

你好嗎?

對於錯過的代碼,請釋放應用程序將使用的scopo,如果要使用Google日歷,則必須使用以下代碼:

$ client-> addScope(' https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/calendar.readonly ');

有關范圍的更多信息: Google API的OAuth 2.0范圍

:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM