-1

我正在尝试通过 Google 电子邮件设置 API 更新签名。域是 EDU 帐户,相关用户是超级管理员。成功检索 OAuth 2.0 令牌后,我发出以下 php curl 代码:

$mydomain = '<mydomain.com>';
$myuser = '<myusername>';
$token = '<mytoken>';   
$url = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/'.$mydomain.'/'.$myuser.'/signature'
$data = '<?xml version="1.0" encoding="utf-8"?>
         <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">
         <apps:property name="signature" value="blabla" />
         </atom:entry>';

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml', 'Authorization: Bearer '.$token));
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
   $output = curl_exec ($ch); 

   curl_close ($ch); 

结果是:

You are not authorized to access this API. Error 403

由于此处提到的关于获得授权时的 client_id 的其他问题,我已尝试使用 gserviceaccount.com 地址和 googleusercontent.com 地址进行上述操作,结果相同。

我在这里做错了什么?

4

1 回答 1

0

回答我自己的问题:在与 Google 代表交谈后,我了解到电子邮件设置 api 不能通过标准的“网络应用”授权使用,而需要通过“服务帐户”使用:

https://developers.google.com/identity/protocols/OAuth2ServiceAccount

于 2015-05-08T11:47:40.097 回答