OAuth java 实现,缺少 oauth_callback

发布于 2024-08-27 02:10:49 字数 1045 浏览 6 评论 0原文

我的问题是我在尝试从雅虎获取请求令牌时遇到错误。该错误表明我缺少 oauth_callback 参数,是的,我错过了它,因为我不需要它。我读过,如果我不想使用它(桌面应用程序),我需要将其设置为“oob”值。我也这样做了,但没有效果。如果我将其设置为 null,也会发生同样的情况。我使用 OAuth for java: http://oauth.googlecode.com/svn/code /java/核心/

OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
                                                                        "https://api.login.yahoo.com/oauth/v2/request_auth",
                                                                        "https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());

My problem is I get error while trying to get request token from Yahoo. The error says Im missing oauth_callback parameter and yes I miss it because I dont need it. Ive read I need to set it to "oob" value if I dont want to use it(desktop app). And I did that but to no avail. If I set it to null the same happens. Im using OAuth for java: http://oauth.googlecode.com/svn/code/java/core/

OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
                                                                        "https://api.login.yahoo.com/oauth/v2/request_auth",
                                                                        "https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

2024-09-03 02:10:49

您是否尝试过使用 Scribe

我也遇到了 OAuth java 库的问题,所以我开发了这个库。它几乎是跨提供商的,并且比您正在使用的有更好的文档。

如果它不适用于雅虎,您可以轻松扩展它,创建您自己的 Provider

希望有帮助!

Have you tried using Scribe?

I also had problems with OAuth java libs so I developed that one. It's pretty much cross provider and better documented than the one you're using.

If it does not work with Yahoo you can easily extend it creating your own Provider

Hope that helps!

虐人心 2024-09-03 02:10:49

java OAuthMassage 类中存在问题,我通过添加到 addRequiredParameters 方法这一行来解决它
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK,consumer.callbackURL);
}
如果您仍然遇到此问题,我可以帮助您:[电子邮件受保护]

there is a problem in the java OAuthMassage class, I resolved it by adding to addRequiredParameters method thie line
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
}
if you still have this problem I can help you: [email protected]

稍尽春風 2024-09-03 02:10:49

我没有使用过该库,但看起来它没有正确处理回调 URL。自 OAuth 1.0a (http://oauth.net/advisories/2009-1/http://oauth.net/core/1.0a/),回调 URL 需要要在第一次调用中发送以获取请求令牌(而不是在客户端调用中进行授权),并且该库似乎尚未更新以执行此操作(至少从查看代码来看)。我假设雅虎需要该参数。

I haven't used that library, but it looks like it isn't properly handling the callback URL. Since OAuth 1.0a (http://oauth.net/advisories/2009-1/ and http://oauth.net/core/1.0a/), the callback URL needs to be sent in the first call to get the request token (not in the client-side call to authorise it), and it seems that this library hasn't been updated to do this (at least from looking at the code). I assume that Yahoo requires the parameter to be there.

从此见与不见 2024-09-03 02:10:49

不确定最初的问题是否已解决,但想指出雅虎上周发布的新 Java OAuth SDK:
http://developer.yahoo.net/blog/archives/2010/ 07/yos_sdk_for_java.html

尝试使用 Java 通过 OAuth 访问雅虎服务的开发人员可能会发现此 SDK 的部分内容很有帮助。

Not sure if the original problem was ever solved, but wanted to point to a new Java OAuth SDK that Yahoo released last week:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html

Developers trying to access Yahoo's services via OAuth with Java may find parts of this SDK helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文