簡體   English   中英

Google OAuth錯誤缺少必填參數:grant_type

[英]Google OAuth error Required parameter is missing: grant_type

我正在嘗試以下代碼:

import requests
url_token = 'https://accounts.google.com/o/oauth2/token'
params = {
    'code': request.values.get('code', '', type=str),
    'client_id': app.config['SOCIAL_GOOGLE']['consumer_key'],
    'client_secret': app.config['SOCIAL_GOOGLE']['consumer_secret'],
    'redirect_uri': urllib.quote_plus("https://example.com/google/code"),
    'grant_type': 'authorization_code'
}
out = requests.post(url_token, params=params)

在Flask中使用Python-Request。 但是我得到了錯誤響應:

ERROR - out={
   "error" : "invalid_request",
   "error_description" : "Required parameter is missing: grant_type"
}

這是標准的POST請求。 關於Google為什么看不到grant_type參數的任何提示? 還是誤導性錯誤消息?

params用於在GET請求中向URL添加查詢參數, data用於將數據傳遞給POST請求,因此您應將POST參數的形式傳遞為:

out = requests.post(url_token, data=params)

請參閱以下位置的文檔: http : //docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM