我正在尝试将雅虎集成到我的应用程序中。我正在努力,
private static final String YAHOO_CALLBACK_URI = "MyApp://oauth";
public static final String YAHOO_REQUEST_TOKEN_URL = "http://api.login.yahoo.com/oauth/request_token";//api.login.yahoo.com
public static final String YAHOO_ACCESS_TOKEN_URL = "http://api.login.yahoo.com/oauth/access_token";
public static final String YAHOO_AUTHORIZE_URL = "http://api.login.yahoo.com/authorize";
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(YAHOO_CONSUMER_KEY, YAHOO_CONSUMER_SERECT_KEY);
OAuthProvider provider = new CommonsHttpOAuthProvider(YAHOO_REQUEST_TOKEN_URL, YAHOO_ACCESS_TOKEN_URL, YAHOO_AUTHORIZE_URL);
provider.setOAuth10a(true);
try {
String authUrl = provider.retrieveRequestToken(consumer, YAHOO_CALLBACK_URI);// Can I pass Null for callback url.
System.out.println("AuthURL = " + authUrl);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
获取
oauth.signpost.exception.OAuthCommunicationException:与服务提供商的通信失败:服务提供商响应错误:404(未找到)
为什么我们无法检索请求 token 。
最佳答案
- 确保您在 Yahoo 上的应用已注册为基于网络的应用。当您注册为基于 Web 的应用程序时,请提供您选择的有效应用程序 URL 和应用程序域(两者应该是同一域),但尚未被其他任何人使用。例如,我有我拥有的网站的网址。这也将用作消费者中的回调网址。
- 不要调用“MyApp://oauth”,而是提供有效的 http 回调 URL(与注册应用程序时使用的 URL 相同)。有了这些,上面的代码应该可以工作了。
- 打开一个新的 Webview 并调用 authUrl。一旦您的应用程序获得授权,请通过覆盖“onPageStarted”方法来拦截对您的应用程序 URL 的调用。在那里,通过启动指向“MyApp://oauth”的新 Intent 来回调您的应用。
如果上述任何步骤让您感到困惑,请告诉我 - 我非常乐意为您提供帮助。
关于android - 无法检索 Android 中雅虎集成的请求 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6960632/