我想使用Twitter oAuth
。我看了不同的例子和教程。所以我從一開始就開始了。我已經在dev.twitter.com,
上註冊了應用程序,沒關係。消費者密鑰和消費者祕密可用。Android:Twitter oAuth授予OAuthNotAuthorizedException錯誤
然後我添加signpost-core
和signpost-commonhttp
罐子我libs文件夾和定義的constans這樣的:
private static final String CONSUMER_KEY = "myConsumerKey";
private static final String CONSUMER_SECRET = "myConsumerSecretKey";
private static String ACCESS_KEY = null;
private static String ACCESS_SECRET = null;
private static final String REQUEST_URL = "http://twitter.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://twitter.com/oauth/access_token";
private static final String AUTH_URL = "http://twitter.com/oauth/authorize";
private static final String CALLBACK_URL = "OauthTwitter://twitter";
private static final String PREFERENCE_FILE = "twitter_oauth.prefs"
private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
CONSUMER_KEY, CONSUMER_SECRET);
private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);
這裏是我的清單:
<data android:scheme="OauthTwitter" android:host="twitter"/>
最後這裏是我的單擊事件:
try {
String authURL = provider.retrieveRequestToken(consumer, CALLBACK_URL);
Log.d("OAuthTwitter", authURL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)));
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
當我點擊我看到這件T按鈕種族:
07-23 06:24:48.428: W/System.err(15121): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.
07-23 06:24:48.433: W/System.err(15121): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:243)
07-23 06:24:48.433: W/System.err(15121): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:193)
07-23 06:24:48.433: W/System.err(15121): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:74)
07-23 06:24:48.438: W/System.err(15121): at com.exampel.app.MyActivity$1.onClick(MyActivity.java:71)
07-23 06:24:48.438: W/System.err(15121): at android.view.View.performClick(View.java:2364)
07-23 06:24:48.438: W/System.err(15121): at android.view.View.onTouchEvent(View.java:4179)
07-23 06:24:48.438: W/System.err(15121): at android.widget.TextView.onTouchEvent(TextView.java:6541)
07-23 06:24:48.443: W/System.err(15121): at android.view.View.dispatchTouchEvent(View.java:3709)
07-23 06:24:48.443: W/System.err(15121): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-23 06:24:48.443: W/System.err(15121): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-23 06:24:48.448: W/System.err(15121): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-23 06:24:48.448: W/System.err(15121): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-23 06:24:48.448: W/System.err(15121): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1665)
07-23 06:24:48.448: W/System.err(15121): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
07-23 06:24:48.453: W/System.err(15121): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
07-23 06:24:48.453: W/System.err(15121): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1649)
07-23 06:24:48.453: W/System.err(15121): at android.view.ViewRoot.handleMessage(ViewRoot.java:1694)
07-23 06:24:48.458: W/System.err(15121): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 06:24:48.458: W/System.err(15121): at android.os.Looper.loop(Looper.java:123)
07-23 06:24:48.458: W/System.err(15121): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-23 06:24:48.463: W/System.err(15121): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 06:24:48.463: W/System.err(15121): at java.lang.reflect.Method.invoke(Method.java:521)
07-23 06:24:48.463: W/System.err(15121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-23 06:24:48.463: W/System.err(15121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-23 06:24:48.468: W/System.err(15121): at dalvik.system.NativeStart.main(Native Method)
我敢肯定,有關密鑰和密碼,但仍然是相同的。我究竟做錯了什麼?任何建議都會很棒。
是的,這對我有用!非常感謝。 – Martin 2012-07-23 13:02:33