1
我试图使用php库获取邮件列表。这是工作,但现在它会显示以下错误:Gmail API获取列表“发生了错误:{”error“:”invalid_grant“,”error_description“:”Bad Request“}”PHP
发生错误:{ “错误”: “invalid_grant”, “ERROR_DESCRIPTION”: “错误的请求”}
阵列(0) {}
代码:
function getList($lastsynctime='') {
// Get the API client and construct the service object.
$client = $this->getClient();
$service = new Google_Service_Gmail($client);
// $newTime = strtotime('-15 minutes');
if ($lastsynctime =='') {
$newTime = strtotime('-60 day');
$after = strtotime(date('Y-m-d H:i:s', $newTime));
}else{
$after = strtotime($lastsynctime);
}
// Print the labels in the user's account.
$userId = 'me';
$pageToken = NULL;
$messages = array();
$opt_param = array();
do {
try {
if ($pageToken) {
$opt_param['pageToken'] = $pageToken;
}
$opt_param['q'] = "from:[email protected] after:$after";
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);
echo "<pre>";var_dump($messagesResponse);
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
} while ($pageToken);
return $messagesResponse;
}
感谢您的建议。它解决了我的问题。 –
很高兴知道。 –