【发布时间】:2014-03-11 11:51:05
【问题描述】:
我想使用 Admin SDK 下载邮箱,但无法正常工作。我找不到我需要定义的范围。我正在使用服务帐号。
为了准备下载,您必须向https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/{domain name}/{source user name} 发出POST 请求,但没有audit.mail 范围或类似的东西。
这是我的要求:
<?php
$client = new \Google_Client();
$cred = new \Google_Auth_AssertionCredentials(
'***@developer.gserviceaccount.com',
array(
'https://apps-apis.google.com/a/feeds/compliance/audit',
),
file_get_contents($path)
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$url = "https://apps-apis.google.com/a/feeds/compliance/audit/publickey/" . $domain;
$req = new \Google_Http_Request($url, 'POST');
$req->setPostBody($xml);
$token = json_decode($client->getAccessToken(), true);
$req->setRequestHeaders(
array(
'Content-Type'=> 'application/atom+xml; charset=utf-8',
'Authorization'=> 'Bearer ' . $token['access_token'] . '',
)
);?>
但我收到 403 错误:You are not authorized to access this API.。
使用 PHP API 和服务帐户下载邮箱的最佳方法是什么?
【问题讨论】:
-
什么是 $client?你是如何认证的?
-
@ViniciusPinto 我正在使用 Google_Auth_AssertionCredentials()。我更新了我的帖子。
-
我认为正确的范围是你在帖子中提到的那个,而不是代码中的那个,但我相信你已经尝试过了。不知道还有什么问题。
-
没错:我尝试了很多不同的示波器,但都没有奏效。
标签: php google-api google-api-php-client google-admin-sdk google-email-audit-api