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;
}
感謝您的建議。它解決了我的問題。 –
很高興知道。 –