3

我想使用 Admin SDK 下载邮箱,但无法正常工作。我找不到我需要定义的范围。我正在使用服务帐户。

为了准备下载,您必须向 发出POST请求https://apps-apis.google.com/a/feeds/compliance/audit/mail/export/{domain name}/{source user name},但没有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 和服务帐户下载邮箱的最佳方法是什么?

4

1 回答 1

2

电子邮件审核 api 范围为:https ://apps-apis.google.com/a/feeds/compliance/audit/

您是否在管理控制台中为您的服务帐户授予了具有适当范围的第三方客户端访问权限?范围设置必须在您的代码和管理控制台中进行设置。

这是有关如何正确设置服务帐户的完整说明(示例在驱动器中,因此您应该根据自己的情况更改电子邮件审核 api 的范围)

https://developers.google.com/drive/web/delegation

确保完成“将域范围的权限委派给您的服务帐户”的步骤。

最后,如果您查看 PHP 代码示例,您会发现您将需要范围、您尝试模拟的用户和您的服务帐户。

于 2014-03-13T23:37:13.913 回答