Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Login does not work if Twitter app is not installed in device

This may be the most asked question on SO, but i am still unable to fix my problem. I have checked this, this and many others, but the problem is still there.

If twitter app is installed on user's device, everything works fine, but if its not there i get the following error message.

Invalid json: Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403 at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)

I defined https://www.google.com as a callback URL, and following is my implementation.

//Activity Class

 Twitter.initialize(this);

 button.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {

                TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
                TwitterAuthToken authToken = session.getAuthToken();
                String token = authToken.token;
                String secret = authToken.secret;

                login(session);

            }

            @Override
            public void failure(TwitterException exception) {
                Log.d("Failure", "failure");
            }
        });

Strings.xml

   <string name="com.twitter.sdk.android.CONSUMER_KEY">---</string>
   <string name="com.twitter.sdk.android.CONSUMER_SECRET">---</string>

Gradle

compile 'com.twitter.sdk.android:twitter:3.1.1'

EDIT

I have also tried twittersdk:// and twitterkit-consumer-key:// as callback Url

like image 637
dev90 Avatar asked Jul 15 '18 14:07

dev90


People also ask

Why can't I log into Twitter on my phone?

General troubleshootingTry clearing cache and cookies for your device's mobile browser. You can clear cache and cookies from the settings menu for your mobile browser. Check to make sure that javascript is enabled on your device.

Can you have a Twitter account without the app?

Just open Twitter in Chrome, Safari, or another browser—use an incognito window if you're already signed in. When you visit the Twitter homepage in a desktop browser without signing in, it asks you to log in before doing anything. However, we'll show you other links that let you get around this.

Why is my device not compatible with Twitter?

Twitter supports MP4 and MOV videos with H. 264 encoding and AAC audio. It does not accept other video formats like MKV, AVI, FLV, or WebM. Also, if you export the video in a very high resolution, say 4K or 2K with a high fps, Twitter may not support it.


1 Answers

Refer this link here.

We need to set twittersdk:// inside callback URL as described in link like below.

  1. go to your twitter app setting https://apps.twitter.com/ >> Tab
    settings >> Fill this text "twittersdk://" to your callback URL
    field( I found it in lib class)
  2. Save your update
  3. check out your app again.

It worked just by setting twittersdk:// as one callback URL, without appending anything.

like image 164
fightingCoder Avatar answered Nov 13 '22 20:11

fightingCoder