Google 电子邮件设置 api 错误 403 php curl
Google email settings api error 403 with php curl
我正在尝试通过 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
因为here关于client_id获得授权时提到的其他问题,我已经用gserviceaccount.com地址和googleusercontent.com地址尝试了上面的方法,用同样的结果。
我在这里做错了什么?
回答我自己的问题:在与 Google 代表交谈后,我了解到电子邮件设置 api 无法通过标准 "web app" 授权使用,但需要通过一个 "service account":
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
我正在尝试通过 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
因为here关于client_id获得授权时提到的其他问题,我已经用gserviceaccount.com地址和googleusercontent.com地址尝试了上面的方法,用同样的结果。
我在这里做错了什么?
回答我自己的问题:在与 Google 代表交谈后,我了解到电子邮件设置 api 无法通过标准 "web app" 授权使用,但需要通过一个 "service account":
https://developers.google.com/identity/protocols/OAuth2ServiceAccount