Mr. Mad
Mr. Mad

Reputation: 1238

Twitter issue in android:: com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 400

can you please resolve the issue having while integrating the twitter login in my android app.

here is the issues :

Twitter: Failed to get request token com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 400 at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5643) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

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:94) at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:191) at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5643) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

And here is my code :

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET))
            .debug(true)
            .build();
    Twitter.initialize(config);
    setContentView(R.layout.layout_list);

    nameit = (TextView) findViewById(R.id.nameit);
    loginButton = (TwitterLoginButton) findViewById(R.id.login_button);

    loginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            // Do something with result, which provides a TwitterSession for making API calls
            try {
                TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
                TwitterAuthToken authToken = session.getAuthToken();
                String token = authToken.token;
                String secret = authToken.secret;
                TwitterSession session1 = result.data;
                String name = session1.getUserName();
                nameit.setText("Welcome " + name);
                Log.e("DATTTA", session.getUserId() + "");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void failure(TwitterException exception) {
            // Do something on failure
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    loginButton.onActivityResult(requestCode, resultCode, data);
}

Sorry for bad English and Thanks in advance.

Upvotes: 3

Views: 2349

Answers (2)

sai Pavan Kumar
sai Pavan Kumar

Reputation: 1177

I had same problem and I solved it by the following methods Those are

1) checked for callback URL and added extra CallBack URL i.e

twittersdk://

adding the above url because if we don’t have twitter app installed the twittersdk tries to open in web view so we have to add this callback url

2)Added this code before SetContentView method in onCreate

//Initialize twitter SDK
TwitterConfig config = new TwitterConfig.Builder(this)
                .logger(new DefaultLogger(Log.DEBUG))
                .twitterAuthConfig(new TwitterAuthConfig(YOUR_CONSUMER_API_KEY, YOUR_CONSUMER_API_SECRET))
                .debug(true)
                .build();
Twitter.initialize(config);

Upvotes: 0

MissTechie
MissTechie

Reputation: 79

I had same problem and I resolved it by following below steps.

Go to Twitter Application Management Click on the 'app' on which you are currently working Click on 'Settings' tab

1) Callback URL: Insert any valid URL like http://www.google.com The callback URL is used to redirect you on browser when the twitter app is not installed in your device.

2) Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback URL):Verify that it is unchecked

3) No need to initialise your twitter sdk in your application class instead initialise it as below:

    private void init(){

    TwitterAuthConfig authConfig = new TwitterAuthConfig(getResources().getString(R.string.consumer_key), getResources().getString(R.string.secrete_key));
    TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(authConfig)
            .debug(true)
            .build();
    Twitter.initialize(config);

}

Thanks..

Upvotes: 3

Related Questions