当使用下面的代码来尝试列出了我刚刚成立了一个全新的Gmail帐户收到的消息,我得到无法listUserMessages() - 500后端错误
[Google_Service_Exception] Error calling GET https://www.googleapis.com/gmail/v1/users/myGmailAccount%40gmail.com/messages: (500) Backend Error
我知道验证部分正常工作,因为我可以对this example中显示的内容进行小修改并查询书籍API。下面是我用来尝试查询最近收到的消息我已经授权给Gmail的访问API的代码...
const EMAIL = '[email protected]';
private $permissions = [
'https://www.googleapis.com/auth/gmail.readonly'
];
private $serviceAccount = '[email protected]';
/** @var Google_Service_Gmail */
private $gmail = null;
/** @var null|string */
private static $serviceToken = null;
public function __construct()
{
$client = new Google_Client();
$client->setApplicationName($this->applicationName);
$this->gmail = new Google_Service_Gmail($client);
//authentication
if (isset(self::$serviceToken)) {
$client->setAccessToken(self::$serviceToken);
}
$credentials = new Google_Auth_AssertionCredentials(
$this->serviceAccount,
$this->permissions,
$this->getKey()
);
$client->setAssertionCredentials($credentials);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($credentials);
}
self::$serviceToken = $client->getAccessToken();
}
public function getMessages()
{
$this->gmail->users_messages->listUsersMessages(self::EMAIL);
}
:
500让我相信这是一个内部错误gmail API或我错过了PHP客户端未验证的内容。
我已经登录到Web界面中找到。 API资源管理器正常工作。列表标签抛出相同的错误。我会给另一个用户一个尝试....客户端ID:10391 – Webnet 2014-10-06 18:05:48
我尝试使用其他用户并遇到相同的错误。 – Webnet 2014-10-06 18:16:50
当您使用上面链接的APIs浏览器站点为用户时,情况如何?你能否在开发者控制台确认你的认证设置?例如在“API> Credentials”中检查oauth2,客户端类型等,并确保您在“API> Consent Screen”上设置了项目名称和电子邮件。 – 2014-10-06 20:38:37