Twitter autenthication android without twitter app


#1

I’m using fabric twitter authentication for an android app ,and it works only if I have the twitter official app installed in the phone without the twitter app I get this exception when I try to authenticate. Is mandatory to have install the twitter app on your phone to authenticate with twitter?

06-09 19:00:41.574 12893-13421/client.tclient.com.client E/SharedPreferencesImpl: Couldn't create directory for SharedPreferences file /data/user/0/client.tclient.com.client/shared_prefs/com.crashlytics.prefs.xml
06-09 19:00:43.574 12893-12893/client.tclient.com.client E/ApkAssets: Error while loading asset assets/natives_blob_64.bin: java.io.FileNotFoundException: assets/natives_blob_64.bin
06-09 19:00:43.575 12893-12893/client.tclient.com.client E/ApkAssets: Error while loading asset assets/snapshot_blob_64.bin: java.io.FileNotFoundException: assets/snapshot_blob_64.bin
06-09 19:00:44.342 12893-12893/client.tclient.com.client E/Twitter: Invalid json: <?xml version="1.0" encoding="UTF-8"?>
                                                                    <hash>
                                                                      <error>Desktop applications only support the oauth_callback value 'oob'</error>
                                                                      <request>/oauth/request_token</request>
                                                                    </hash>

                                                                    com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $
                                                                        at com.google.gson.JsonParser.parse(JsonParser.java:65)
                                                                        at com.google.gson.JsonParser.parse(JsonParser.java:45)
                                                                        at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:136)
                                                                        at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:125)
                                                                        at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:58)
                                                                        at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:110)
                                                                        at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
                                                                        at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                     Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $
                                                                        at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1572)
                                                                        at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1421)
                                                                        at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:544)
                                                                        at com.google.gson.stream.JsonReader.peek(JsonReader.java:427)
                                                                        at com.google.gson.JsonParser.parse(JsonParser.java:60)
                                                                        at com.google.gson.JsonParser.parse(JsonParser.java:45) 
                                                                        at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:136) 
                                                                        at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:125) 
                                                                        at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:58) 
                                                                        at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:110) 
                                                                        at com.twitter.sdk.android.core.Callback.failure(Callback.java:45) 
                                                                        at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53) 
                                                                        at android.os.Handler.handleCallback(Handler.java:739) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                        at android.os.Looper.loop(Looper.java:148) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
06-09 19:00:44.343 12893-12893/client.tclient.com.client E/Twitter: Failed to get request token
                                                                    com.twitter.sdk.android.core.TwitterApiException: 401 Authorization Required
                                                                        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
                                                                        at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
                                                                        at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
                                                                        at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                        at retrofit.Platform$Android$2$1.run(Platform.java:142)
                                                                        at java.lang.Thread.run(Thread.java:818)
06-09 19:00:44.383 12893-12893/client.tclient.com.client E/Twitter: Authorization completed with an error
                                                                    com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
                                                                        at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
                                                                        at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:213)
                                                                        at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
                                                                        at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    
    
        android twitter

#2

Hey @AFS_1984,

No, it’s not required to have Twitter app installed on your device. For full information, check it out here: https://docs.fabric.io/android/twitter/authentication.html#log-in-with-twitter

The summary version:

When attempting to obtain an authentication token, the Kit will use the locally installed Twitter app to offer a single sign-on experience. If the Kit is unable to access the authentication token through the Twitter app, it falls back to using a web view to finish the OAuth process.


#3

And I have to set up something to use the web view? without he app it launches the exception of the first post,and I have followed the documentation example.

Thank you.


#4

You’d need to keep a strong reference as mentioned here: https://docs.fabric.io/android/digits/digits.html#configure-the-button-in-an-activity

If that’s still not working for you, please share more of your code and which version of Digits you’re using.


#5

Solved, I didn’t know that I have to set a callback url ,now I can start start session without the twitter app installed on the phone.


#6

Glad you’re all set and happy coding :slight_smile:


#7