如何使用 Grails oauth 插件获取访问令牌?
我已经尝试这个有一段时间了。我能够毫无问题地获取请求令牌。但是当我尝试将其交换为访问令牌时,出现以下错误:
2011-07-17 22:19:19,649 [http-8080-1] 错误 oauth.OauthService - 无法获取访问令牌! (消费者名称=谷歌, requestToken=[密钥:4/Azm6wQDW85iYVmeb4ogCAl70D_89, 秘密:Zrh9saEDJcgCo83QejOu28sU, authUrl:https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=4%2FAzm6wQDW85iYVmeb4ogCAl70D_89, isOAuth10a:true]) oauth.signpost.exception.OAuthCommunicationException:通信 与服务提供商失败:服务提供商响应错误: 400(错误请求
这是控制器中的代码:
def OauthService
if (session.oauthToken == null) {
flash.message = "The token could no be retrieved... Please try again"
redirect(uri:"/")
}
def requestToken = OauthService.fetchRequestToken('google')
def accessToken = OauthService.fetchAccessToken('google', requestToken)
我一直在玩它,但它似乎从来没有以任何方式工作。有人有任何想法吗?
I have been trying this for quite a while now. I am able to fetch the request token no problem. But when i try to exchange it for the access token I get the following error:
2011-07-17 22:19:19,649 [http-8080-1] ERROR oauth.OauthService -
Unable to fetch access token! (consumerName=google,
requestToken=[key:4/Azm6wQDW85iYVmeb4ogCAl70D_89,
secret:Zrh9saEDJcgCo83QejOu28sU,
authUrl:https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=4%2FAzm6wQDW85iYVmeb4ogCAl70D_89,
isOAuth10a:true])
oauth.signpost.exception.OAuthCommunicationException: Communication
with the service provider failed: Service provider responded in error:
400 (Bad Request
Here is the code in the controller:
def OauthService
if (session.oauthToken == null) {
flash.message = "The token could no be retrieved... Please try again"
redirect(uri:"/")
}
def requestToken = OauthService.fetchRequestToken('google')
def accessToken = OauthService.fetchAccessToken('google', requestToken)
I have been playing about with it but it never seems to work any way I do it. Has anybody got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 OAuth 插件文档,它会提到某些 Google API 需要
scope
属性在 OAuth 配置中设置(在 Config.groovy 中)。考虑到 Google 服务器返回400 Bad Request
,可能值得仔细检查。此外,为
grails.app.service.org.grails.plugins.oauth
和grails.app.controller.org.grails.plugins.oauth
包启用调试日志记录可能会提供更多线索。If you look at the OAuth plugin docs, it mentions that some Google APIs require the
scope
attribute to be set in the OAuth config (inConfig.groovy
). Might be worth double-checking, considering the Google server is returning400 Bad Request
.Also, enabling debug logging for the
grails.app.service.org.grails.plugins.oauth
andgrails.app.controller.org.grails.plugins.oauth
packages might provide some more clues.