2015-03-08 112 views
0

我有想从提供PandaDocs API的REFRESH_TOKEN的ACCESS_TOKEN一个问题..... API调用OAuth2.0的刷新令牌问题PandaDocs

什么是正确的参数,以便获得发送来自刷新令牌的新ACCESS_TOKEN?

我存储了我最初收到的刷新标记,当我第一次通过身份验证以上传要签名的文档时。我现在想要使用刷新令牌来获取新的访问令牌,以检查文档上签名的状态。

我想获得一个新的访问令牌使用我存储的刷新令牌,但我一直得到的grant_type是无效的。

这是我的代码..

$token = '(refreshtokenhere)'; 
    $url = "https://app.pandadoc.com/oauth2/access_token"; 
    $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2'; 
     $ch = curl_init(); 
     $headr = array(); 

     $headr[] = 'Content-Type: application/json;charset=UTF-8'; 


     curl_setopt($ch, CURLOPT_HTTPHEADER,$headr); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_HEADER, FALSE); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
     curl_setopt($ch, CURLOPT_VERBOSE, 1); 
     curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 

     $postfields['grant_type'] = 'refresh_token'; 
     $postfields['refresh_token'] = $token; 
     $postfields['client_id'] = CLIENT_ID; 
     $postfields['client_secret'] = CLIENT_SECRET; 


     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 


     echo $ret = curl_exec($ch); // 
+0

你没有提到你从哪里得到这个令牌或者是什么 – 2015-03-08 19:15:26

+0

我有我第一次通过身份验证时保存的refresh_token。我存储它重用它.. – 2015-03-08 19:28:09

+0

它来自PandaDocs ... – 2015-03-08 19:28:29

回答

1

检查API文档。 grant_type应包含授权码。

https://developers.pandadoc.com

http://tools.ietf.org/html/rfc6749

编辑:

grant_type应该是因为它是在你的代码,即文本字符串 “refresh_token” 所示。

当您发现删除内容类型标题,以便发布字段正确发送。

+0

我已经尝试过,它仍然给我 “error_description”:“否'grant_type'包含在请求中。“,”error“:”invalid_request“} – 2015-03-08 19:39:57

+0

然后你的authorisation_code必须是坏的 – 2015-03-08 19:43:09

+0

如果authorisation_code不好,它会声明不是说没有包含grant_type?我使用的代码是REFRESH_TOKEN,它在我认证时给了我。也许在我的代码中还有其他错误? – 2015-03-08 19:46:14

0

在您传递的值的那个标记字段中。它应该包含先前获取的刷新令牌,而不是访问令牌。

+0

在评论中他清楚地表示他正在重新使用他以前保存的刷新标记。 – hybrid 2015-09-11 10:11:36