Can't login using Twitter Android api


#1

Hi.
I’m working with Eclipse. I installed Fabric plugin for it and integrated Twitter api using it. After integration had finished I couldn’t run the app. I need only login functionality so I removed “kit-libs” folder from my app and connected Twitter libraries as Android projects like this:
MyApp<-Fabric<-Twitter<-TwitterCore
Application runs fine. I also left meta data with io.fabric.ApiKey in manifest and left fabric.properties file with fabricSecret in my project.

Here’s the code I use to initialize Fabric

TwitterAuthConfig authConfig = new TwitterAuthConfig(
			TWITTER_KEY, TWITTER_SECRET);
Fabric.with(application, new TwitterCore(authConfig));

I use TwitterCore kit cause I only need login function (to get user id and name) and if I’m using Twitter kit then I need also include Digits etc. libraries otherwise I’m getting NoClassDefFoundError in runtime. So actually Twitter library project mentioned above is unnecessary.
I also declared OAuthActivity and ShareEmailActivity in my manifest.
I don’t want to use TwitterLoginButton so I used 2 ways to login user:

  1. Using TwitterAuthClient.authorize() method.

  2. Using TwitterCore.getInstance().login() method.
    Don’t know the difference between them but trying to login using any of them leads to error:

    07-27 18:12:35.116: E/Twitter(21226): Invalid json: <?xml version="1.0" encoding="UTF-8"?>
    07-27 18:12:35.116: E/Twitter(21226):
    07-27 18:12:35.116: E/Twitter(21226): Desktop applications only support the oauth_callback value 'oob’
    07-27 18:12:35.116: E/Twitter(21226): /oauth/request_token
    07-27 18:12:35.116: E/Twitter(21226):
    07-27 18:12:35.116: E/Twitter(21226): com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.JsonParser.parse(JsonParser.java:65)
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.JsonParser.parse(JsonParser.java:45)
    07-27 18:12:35.116: E/Twitter(21226): at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:136)
    07-27 18:12:35.116: E/Twitter(21226): at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:125)
    07-27 18:12:35.116: E/Twitter(21226): at com.twitter.sdk.android.core.TwitterApiException.(TwitterApiException.java:58)
    07-27 18:12:35.116: E/Twitter(21226): at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:110)
    07-27 18:12:35.116: E/Twitter(21226): at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
    07-27 18:12:35.116: E/Twitter(21226): at android.os.Handler.handleCallback(Handler.java:739)
    07-27 18:12:35.116: E/Twitter(21226): at android.os.Handler.dispatchMessage(Handler.java:95)
    07-27 18:12:35.116: E/Twitter(21226): at android.os.Looper.loop(Looper.java:135)
    07-27 18:12:35.116: E/Twitter(21226): at android.app.ActivityThread.main(ActivityThread.java:5254)
    07-27 18:12:35.116: E/Twitter(21226): at java.lang.reflect.Method.invoke(Native Method)
    07-27 18:12:35.116: E/Twitter(21226): at java.lang.reflect.Method.invoke(Method.java:372)
    07-27 18:12:35.116: E/Twitter(21226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    07-27 18:12:35.116: E/Twitter(21226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    07-27 18:12:35.116: E/Twitter(21226): Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531)
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.stream.JsonReader.peek(JsonReader.java:414)
    07-27 18:12:35.116: E/Twitter(21226): at com.google.gson.JsonParser.parse(JsonParser.java:60)
    07-27 18:12:35.116: E/Twitter(21226): … 15 more
    07-27 18:12:35.116: E/Twitter(21226): Failed to get request token
    07-27 18:12:35.116: E/Twitter(21226): com.twitter.sdk.android.core.TwitterApiException: 401 Authorization Required
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:382)
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
    07-27 18:12:35.116: E/Twitter(21226): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    07-27 18:12:35.116: E/Twitter(21226): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    07-27 18:12:35.116: E/Twitter(21226): at retrofit.Platform$Android$2$1.run(Platform.java:142)
    07-27 18:12:35.116: E/Twitter(21226): at java.lang.Thread.run(Thread.java:818)
    07-27 18:12:35.148: E/Twitter(21226): Authorization completed with an error
    07-27 18:12:35.148: E/Twitter(21226): com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
    07-27 18:12:35.148: E/Twitter(21226): at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
    07-27 18:12:35.148: E/Twitter(21226): at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:215)
    07-27 18:12:35.148: E/Twitter(21226): at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
    07-27 18:12:35.148: E/Twitter(21226): at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
    07-27 18:12:35.148: E/Twitter(21226): at android.os.Handler.handleCallback(Handler.java:739)
    07-27 18:12:35.148: E/Twitter(21226): at android.os.Handler.dispatchMessage(Handler.java:95)
    07-27 18:12:35.148: E/Twitter(21226): at android.os.Looper.loop(Looper.java:135)
    07-27 18:12:35.148: E/Twitter(21226): at android.app.ActivityThread.main(ActivityThread.java:5254)
    07-27 18:12:35.148: E/Twitter(21226): at java.lang.reflect.Method.invoke(Native Method)
    07-27 18:12:35.148: E/Twitter(21226): at java.lang.reflect.Method.invoke(Method.java:372)
    07-27 18:12:35.148: E/Twitter(21226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    07-27 18:12:35.148: E/Twitter(21226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

With message: Failed to get request token.

Can anyone suggest anything on this? Perhaps I didn’t activate my Twitter project somewhere?


#2

your consumer key and/or your secret key is incorrect in your java class. you should write consumer key and consumer secret just as Twitter developer page which use to create an app


#3

The reason was in missing “Callback URL” on Twitter app page. Don’t know why is it necessary but after populating this field login works.

Probably this problem appears only without Twitter app installed on device so login opens web form.


#4