我的目标是更新我域中的所有用户电子邮件签名。
我已经设置了一个具有域范围委派权限的服务帐户。但我遇到了这个错误:
{
"error": {
"errors": [
{\n
"domain": "global",
"reason": "failedPrecondition",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
我使用的请求与 API Explorer 执行的请求相同。所以它应该是格式良好的......
在 API 资源管理器中,它也不能正常工作,我有这个答案:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Delegation denied for vivien@mydomain.com"
}
],
"code": 403,
"message": "Delegation denied for vivien@mydomain.com"
}
}
好像我有权限问题,但我不知道为什么。
这是我的 PHP 测试代码以供参考:
public function updateSignAction(){
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$this->get('kernel')->getRootDir().'/../app/Resources/files/mydomain.json');
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName("demo");
$client->addScope([
"https://www.googleapis.com/auth/gmail.settings.basic",
"https://www.googleapis.com/auth/gmail.settings.sharing"
]);
//$client->setSubject('vivien@mydomain.com');
$httpClient = $client->authorize();
$response = $httpClient->put(
'https://www.googleapis.com/gmail/v1/users/vivien@mydomain.com/settings/sendAs/test',
[
'json' => [
'signature' => "test-via-api"
]
]
);
return $this->render('AdminBundle:GoogleApi:user/update.html.twig', array(
'response' => $response->getBody()->getContents(),
));
}