【问题标题】:Download a mailbox using Email Audit (Admin SDK)使用电子邮件审核 (Admin SDK) 下载邮箱
【发布时间】: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


【解决方案1】:

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

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

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

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

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

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

【讨论】:

  • 是的,我确实在管理控制台中设置了范围。我已经让 Drive API 正常工作,但无法让电子邮件审核正常工作。
猜你喜欢
  • 1970-01-01
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多