2016-11-09 68 views
-1

我试图从Gmail API得到一个附件 -无效附件令牌的Gmail API

https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get#try-it

令牌是主要的用户令牌 - 我能读这个道理,ID和消息ID电子邮件和是正确的。

我需要解码附件ID吗?
我得到,如果魔神是$p->getBody()['attachmentId']

附件ID是ANGjdJ9jgabAPGnlI7oCAAEvz_Jo-xNYh4-kf9NoCyn-aRPPlf8KuRTsbolmQH0bdDl4Qh3UdfWCBBl8Roaly-rxqRoxTotvIEmls8zqCkFasvFcC-wvQ_6Qun2RM8f8SCDvVpmwguVf​​6fvWfkl1uu5qdu3iR-GzpyU6zLsV0wcwVuiTtPNh8XjAuqKvFk7PaVgDiNW_Lwk_DDEWP8UxfTqw2afanJMNY5GrqPLhga6FmarDIh5AiM67tY6x5Vl

我也试试这个在线测试,但有错误。
什么是附件标记?其他令牌?

enter image description here

I测试令牌这里https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=

"scope": " https://mail.google.com/ https://www.googleapis.com/auth/drive ", 
"expires_in": 3518, 
"verified_email": true, 
"access_type": "offline" 

更新1

这个例子

$token = $client->getAccessToken(); 
$authObj = json_decode($token); 
if(isset($authObj->refresh_token)) { 
save_refresh_token($authObj->refresh_token); 
} 


$token = $client->getAccessToken(); 

被阵列不JSON

它是有效
"access_token" => "ya29.Ci-XA8H0Qq33gA00E92Nx9CQufeG3U4NvyHUFbUUzyXcOEp50FbuK-z1hic8aNbxZg" 
    "token_type" => "Bearer" 
    "expires_in" => 3600 
    "id_token" => .... 
"created" => 1479227459 

我不能老是得到refresh_token - 我从AUTH_CODE

$client->setApprovalPrompt('force'); 
      $client->setAccessType ("offline"); 

      $client->authenticate($tokenCode); 

      $token = $client->getAccessToken(); 

ACCESS_TOKEN我有令牌,但没有refresh_token为什么呢?

回答

-1

对于Web服务器应用程序,您应该使用标准OAuth 2.0。您的应用程序会收到短期访问令牌,它可以访问这些资源并刷新令牌以允许长期访问,并确保您在oauth2授权中添加脱机标志。您将收到一个将在3600秒或1小时内过期的令牌,并且过期正常。所以你需要使用刷新令牌来获得新的工作令牌。

这里有您需要的步骤:

$token = $client->getAccessToken(); 
$authObj = json_decode($token); 
if(isset($authObj->refresh_token)) { 
save_refresh_token($authObj->refresh_token); 
} 

保存此refresh_token是很重要的,那么你就可以

$client->refreshToken($your_saved_refresh_token); 
And then set your new access token to the session: 

$_SESSION['access_token'] = $client->getAccessToken(); 

我做了一些研究更新了一下,发现SO票从而可以帮助您了解oauth web流程:How to refresh token with Google API client?