【发布时间】:2014-07-09 19:57:43
【问题描述】:
我正在为 twitter oauth 尝试以下示例应用程序。
http://www.androidsdkforum.com/android-sdk-development/3-oauth-twitter.html
private void askOAuth() {
try {
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token",
"http://twitter.com/oauth/access_token",
"http://twitter.com/oauth/authorize");
String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
} catch (Exception e) {
Log.e(APP, e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
当我运行以下代码时,它会给出如下异常
“oauth.signpost.exception.OAuthNotAuthorizedException:授权失败(服务器回复 401)。如果消费者密钥不正确或签名不匹配,则可能发生这种情况。”
在这条线上String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
我提供了正确的“密钥”和“秘密”,Twitter 是否给了我错误的密钥和秘密?
【问题讨论】:
-
请告诉我在 CALLBACK_URL 中放什么???
-
你的 android 活动 URL 将在 twitter 返回响应后被调用
-
你的 android 活动 URL,一旦 twitter 返回响应就会被调用
-
所以如果我必须加载一个活动..我在回调 url 中放了什么 ..目前我在回调 url 中添加了 someting.com ..这样网页就被加载了..请指导我..