首页 > 解决方案 > (invalid_grant) 缺少代码验证器 google-ads-api

问题描述

正如OAuth Web 应用程序流程所建议的那样。

回调网址就像

https://xxxxxxx:9431/callback_gg/?state=OV8xxxxxx0Nda6B4xxdR6VtAcyBEH&code=4/pAFG4kRxxxx9qLR7Oaxe1-2LYClj7d1EvP7peblfpm5TMEragm1X0Knrs9yLRekxxxxxUC2EcXne_14A4&scope=https://www.googleapis.com/auth/adwords

我正在努力

#If the client opted to allow you to access their account, you will
#receive an authorization code in the response as a query string. 
#This #can be used to retrieve an access and refresh token with the
#following #lines of code
flow.fetch_token(code=auth_code)
credentials = flow.credentials

但我犯了错误

oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Missing code verifier.

我错过了什么吗?我对这个错误感到困惑,因为我正在关注 api doc

标签: google-ads-api

解决方案


该错误信息暗示您需要在您的授权请求中添加code_challenge请求参数和请求参数,并在您的令牌请求中添加请求参数。code_challenge_method=S256code_verifier

这些参数在RFC 7636(OAuth 公共客户端的代码交换证明密钥)中定义。有关 RFC 7636 的技术详细信息,请参阅本文

Google 的文档不是最新的,或者如果您code_verifier在令牌请求中包含 a 时看到相同的错误,则错误消息本身是错误且具有误导性的。


推荐阅读