I am using the sample for the app here https://github.com/itog/Twitter4j-android-Sample and it is working. I use the same method in my app but it return null when I at line
static final String CALLBACK_URL = "oauth://t4jsample"; [Copy the same as the Sample] requestToken = twitter.getOAuthRequestToken(CALLBACK_URL); Here are my manifest
<activity android:name="com.my.app.SharePreviewActivity" android:screenOrientation="portrait" android:theme="@style/Theme.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden|adjustPan" > <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="t4jsample" android:scheme="oauth" /> </intent-filter> </activity> This is other code which I copy the same from the sample app.
private void askOAuth() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(CONSUMER_KEY); configurationBuilder.setOAuthConsumerSecret(CONSUMER_SECRET); Configuration configuration = configurationBuilder.build(); twitter = new TwitterFactory(configuration).getInstance(); try { requestToken = twitter.getOAuthRequestToken(CALLBACK_URL); Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show(); this.startActivity(new Intent(Intent.ACTION_VIEW, Uri .parse(requestToken.getAuthenticationURL()))); } catch (TwitterException e) { e.printStackTrace(); } } Logcat:
09-17 16:37:40.528: W/System.err(21125): at twitter4j.HttpClientBase.request(HttpClientBase.java:53) 09-17 16:37:40.528: W/System.err(21125): at twitter4j.HttpClientBase.post(HttpClientBase.java:82) 09-17 16:37:40.529: W/System.err(21125): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:107) 09-17 16:37:40.530: W/System.err(21125): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:92) 09-17 16:37:40.531: W/System.err(21125): at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:263) 09-17 16:37:40.532: W/System.err(21125): at com.PhotoPreviewActivity.askOAuth(PPActivity.java:320) 09-17 16:37:40.532: W/System.err(21125): at com.my.onShareTwitter(com.my.java:298) 09-17 16:37:40.533: W/System.err(21125): at java.lang.reflect.Method.invokeNative(Native Method) 09-17 16:37:40.534: W/System.err(21125): at java.lang.reflect.Method.invoke(Method.java:511) 09-17 16:37:40.535: W/System.err(21125): at android.view.View$1.onClick(View.java:3687) 09-17 16:37:40.535: W/System.err(21125): at android.view.View.performClick(View.java:4299) 09-17 16:37:40.536: W/System.err(21125): at android.view.View$PerformClick.run(View.java:17549) 09-17 16:37:40.537: W/System.err(21125): at android.os.Handler.handleCallback(Handler.java:725) 09-17 16:37:40.538: W/System.err(21125): at android.os.Handler.dispatchMessage(Handler.java:92) 09-17 16:37:40.539: W/System.err(21125): at android.os.Looper.loop(Looper.java:153) 09-17 16:37:40.539: W/System.err(21125): at android.app.ActivityThread.main(ActivityThread.java:5322) 09-17 16:37:40.540: W/System.err(21125): at java.lang.reflect.Method.invokeNative(Native Method) 09-17 16:37:40.540: W/System.err(21125): at java.lang.reflect.Method.invoke(Method.java:511) 09-17 16:37:40.541: W/System.err(21125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:848) 09-17 16:37:40.541: W/System.err(21125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615) 09-17 16:37:40.541: W/System.err(21125): at dalvik.system.NativeStart.main(Native Method) 09-17 16:37:40.541: I/System.out(21125): [CDS] fix other exception in HttpUrlConnection 09-17 16:37:40.543: W/System.err(21125): null 09-17 16:37:40.543: W/System.err(21125): Relevant discussions can be found on the Internet at: 09-17 16:37:40.543: W/System.err(21125): http://www.google.co.jp/search?q=8e063946 or 09-17 16:37:40.543: W/System.err(21125): http://www.google.co.jp/search?q=c60cdc59 09-17 16:37:40.544: W/System.err(21125): TwitterException{exceptionCode=[8e063946-c60cdc59 8e063946-c60cdc2f], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.2}