'错误':'无效请求','错误描述':'无效的授权类型参数或缺少参数'

时间:2018-08-05 13:53:09

标签: django python-3.x oauth-2.0

我试图从我的api提供程序获取代码后获得 access_token

这是我的职责;

def get_token():
    params = {
        'grant_type' : GRANT_TYPE,
        'client_id' : CLIENT_ID,
        'client_secret' : CLIENT_SECRET,
        'code' : CODE,
        'redirect_uri' : REDIRECT_URI
    }

    HEADERS = {
        'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
    }

    req = requests.post(ACCESS_TOKEN_URL, params=params, headers=HEADERS)

    result = req.json()
    print (result) # in order to see it on the console.

    return result

但是我遇到此错误;

{'error': 'invalid_request', 'error_description': 'Invalid grant_type parameter or parameter missing'}

在这里我该怎么办?

编辑(添加了提供商文档中的相关部分):

文档中的相关部分(因为该文档不是英文的,所以我尝试了尽可能多的翻译):

  

令牌访问
  查询示例

POST http://www.MYPROVIDER.com/oauth/v2/token

?grant_type=authorization_code
&client_id=7_7d67dc7597f034d63775c1d9ae5d9ac7f5750197f
&client_secret=1sowg0oogc4wg4w4o4gh4va57gggwskkgo08m44ksog8kmu88o
&code=Q0ODMI2OGYjMjBkN2mJmYzNkOTE4gzMGRhZDZTcykyOGQ3M2M2YTU2ZGVlMzE2MzB2MYkc5NWzE0ZWNiYjI2MA
&redirect_uri=http%3A//client.example-app.com%2Fauth%2F

HTTP/1.1
     

如果请求成功,则JSON对象将由   HTTP 200代码。

HTTP/1.1 200 OK
Host: your-shop-name.MYPROVIDER.com
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Content-Length: 286

{
  "access_token": "OGE3MzkxNDlhOGY0M2RjZWM1MWI2MWIxZjRmNDJhZThiOGJkOWZlMWIwNzVkYWFlOWFiMDAxYzkwMDlmMDhlMw",
  "expires_in": 21600,
  "token_type": "bearer",
  "scope": "Your access rights will be shown here.",
  "refresh_token": "NjczY2E2NzZiNDJjZWI5NTE2YjZhNTlhYTJmOTQ5MjljN2MwNmUxM2MzODc5YTE4OGVjMDdlYTBiMzY1MWI1Mw"
}

0 个答案:

没有答案