简体   繁体   English

…API调用oAuth2.0刷新令牌问题PandaDocs

[英]… API Call oAuth2.0 Refresh Token issue PandaDocs

I am having a problem trying to get an ACCESS_TOKEN from the REFRESH_TOKEN provided on PandaDocs API.. 我在尝试从PandaDocs API上提供的REFRESH_TOKEN获取ACCESS_TOKEN时遇到问题。

What are the correct parameters to send in order to get a new ACCESS_TOKEN from a refresh token? 为了从刷新令牌中获取新的ACCESS_TOKEN,要发送的正确参数是什么?

I stored the refresh token I originally recieved when I first authenticated to upload a doc to be signed. 我存储了我最初通过身份验证上传文档进行签名时最初收到的刷新令牌。 I now want to use the refresh token to get an new access token in order to check the status of the signatures on the doc. 现在,我想使用刷新令牌来获取新的访问令牌,以便检查文档上签名的状态。

I am trying to get a new access token using the refresh token I stored but I keep getting grant_type is invalid. 我正在尝试使用存储的刷新令牌来获取新的访问令牌,但我不断获取的grant_type无效。

This is my code.. 这是我的代码。

    $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); // 

Check the API documentation. 查看API文档。 The grant_type should contain the authorisation code. grant_type应该包含授权码。

https://developers.pandadoc.com https://developers.pandadoc.com

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

EDIT: 编辑:

grant_type should be as it is shown in your code ie literal string "refresh_token". grant_type应该与您的代码中显示的相同,即文字字符串“ refresh_token”。

As you spotted remove the content type header so the post fields are sent properly. 如发现的那样,删除内容类型标题,以便正确发送post字段。

In that token field which value you are passing. 在该令牌字段中,您要传递哪个值。 It should contain refresh token obtained previously, not access token. 它应该包含以前获得的刷新令牌,而不是访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM