- 谷歌Apps for Business的鏈接到Google Apps Engine帳戶,
- 雲端控制檯 - >註冊應用程序 - > {名} - > Web應用程序 - >的OAuth 2.0客戶端ID
- 雲端控制檯 - >管理API(開)
- 谷歌企業應用套件控制檯 - >安全 - > API訪問(選中)
- 「 - >」 - >第三方的OAuth - > API客戶端(客戶端ID {} .apps.googleusercontent.com)
- 「 - >」 - > 「 - > API Scopes(https://www.googleapis.com/auth/admin.directory.user)
這裏是我到目前爲止,管理SDK,目錄API,用戶:列表 - 任何有關如何做到這一點的PHP示例?
require_once 'google/appengine/api/app_identity/AppIdentityService.php';
use \google\appengine\api\app_identity\AppIdentityService;
function setAuthHeader() {
$access_token =AppIdentityService::getAccessToken("https://www.googleapis.com/auth/admin.directory.user");
return [ sprintf("Authorization: OAuth %s", $access_token["access_token"]) ];
}
$get_contacts_url = "https://www.googleapis.com/admin/directory/v1/users?customer=my_customer";
$headers = implode("\n\r", setAuthHeader());
$opts =
array("http" =>
["http" => ["header" => $headers ]]
);
$context = stream_context_create($opts);
$response = file_get_contents($get_contacts_url, false, $context);
print_r ($response);
的「的access_token」來過就好了,但$返回響應,
{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } }
在Users: List例如在頁面的底部,他們顯示「獲取」請求如下,
GET https://www.googleapis.com/admin/directory/v1/users?customer=my_customer&key={YOUR_API_KEY}
什麼是{YOUR_API_KEY}?我試過每個雲控制檯和Google Apps API,但都沒有運氣。
我是這樣的完全錯誤的,我應該使用完全不同的方法嗎?我一直在爲此奮鬥了一個多星期,並會喜歡任何形式的迴應。謝謝
謝謝。我正在關注[本教程](https://developers.google.com/appengine/docs/php/appidentity/),並且有這樣的印象:如果我的App Engine帳戶已連接到我的Google Apps帳戶,則會以某種方式精簡整個過程。查看[OAuth](https://code.google。「警告:服務帳戶目前受以下Google開發人員服務支持:雲存儲,預測API,URL Shortener,OAuth 2.0授權服務器,BigQuery」。這是否意味着使用PHP,訪問用戶列表不起作用? – user33443
也許Admin SDK包含在Google的「OAuth 2.0授權服務器」部分。我認爲在服務器上嘗試一些代碼是很麻煩的。使用[此示例](http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/prediction/serviceAccount.php)與DirectoryService代替PredictionService。如果它不起作用,請在構建AssertionCredentials對象時嘗試添加sub =參數。 –
AMS