Google Contacts API 的 {'error':'grant_type'}
这是我上一篇文章的延续:Google Contacts 数据 API 给出 500 错误。
您可以在上面的帖子中获取我的代码以及我如何调用 CURL。以前,我间歇性地收到 500 错误,但是当我使用 Google API 控制台休息我的 client_secret 时,它暂时得到了修复。
但现在,当我请求访问令牌时,我突然收到 {error:invalid_grant} 。此错误背后的原因可能是什么?
我搜索了一些论坛,他们说可能会出现此错误,因为在 URL 本身中发送 POST 参数,而不是在 POST 正文中使用它们。但是,对我来说,我的代码似乎没有做任何类似的事情。
此外,没有错误描述以及错误类型。
另外,我实际上对所有参数(例如 client_secret、redirect_uri 甚至 grant_type)进行urlencoding,这可能是原因吗?
我在日志文件中回显了包含 POST 参数的 $post 变量,它显示如下内容:
code=4%2Fsb898gAIIsd20FQk69yPvASTwN1s
&client_id=33137499441.apps.googleusercontent.com
&client_secret=<client_secret>
&redirect_uri=http%3A%2F%2Fwww.plus-one-me.com%2Foauth2callback&grant_type=authorization_code
请随意建议任何更好、更方便的方法来实现 Gmail 联系人的导入。
This is a continuation of my previous post: Google Contacts data API giving 500 Error.
You can get the my code and how I am calling CURL in the above post. Previously, I was getting a 500 Error intermittently, but once I rest my client_secret using Google API console, it was fixed for the time being.
But now, I am getting {error:invalid_grant} all of a sudden when I am requesting for the access token. What might be the reason behind this error?
I searched a few forums where they have said that this error can arise because of sending the POST parameters in the URL itself instead of using them in the POST body. But, to me, it seems that I haven't done anything of that sort in my code.
Also there is no error description along with the error type.
Another thing, I am actually urlencoding all the parameters (e.g client_secret,redirect_uri and even grant_type) , can this be the reason?
I had echoed out the $post variable containing the POST parameters in the log file, and it shows something like the following:
code=4%2Fsb898gAIIsd20FQk69yPvASTwN1s
&client_id=33137499441.apps.googleusercontent.com
&client_secret=<client_secret>
&redirect_uri=http%3A%2F%2Fwww.plus-one-me.com%2Foauth2callback&grant_type=authorization_code
Feel free to suggest any better and convenient way to implement the importing of Gmail contacts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论