TwitterAuthException Failed to get request token


#1

I follow Android Twitter Integration from here but seems it’s not working.

I am using Twitter Login from two different activity i.e. MainActivity and ConfigurationActivity but it work on Main Activity but not on configuration Activity.

Here is crash Report which i am getting.

09-24 14:32:26.443  19773-19773/com. E/Twitter﹕ Failed to get request token
com.twitter.sdk.android.core.TwitterApiException: Unable to resolve host "api.twitter.com": No address associated with hostname
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:390)
        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:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at retrofit.Platform$Android$2$1.run(Platform.java:142)
        at java.lang.Thread.run(Thread.java:818)
09-24 14:32:26.512  19773-19773/com 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:215)
            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:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            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:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
    09-24 14:32:26.512  19773-19773/comE/CMDAConfiguration﹕ Twitter Login Exception:- com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token

I am using auto generated keys using fabric.

Here is MyApplicationClass

public class MyApplication extends Application {
// Note: Your consumer key and secret should be obfuscated in your source code before shipping.
private static final String TWITTER_KEY = xxxxxxxxxxxxxxxxxxxxx";
private static final String TWITTER_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

@Override
public void onCreate() {
    super.onCreate();

    TwitterAuthConfig authConfig =
            new TwitterAuthConfig(TWITTER_KEY,
                    TWITTER_SECRET);

    Fabric.with(this, new Crashlytics(), new Twitter(authConfig));

}

}

Here is my Login Integration code from Configuration Activity.

// twitter login button binding
    loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);

    // Twitter logn button call back
    loginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            // getting usre id , access token and secret token from TwitterSession
            String twitter_id = result.data.getUserId() + "";
            String accessToken = result.data.getAuthToken().token;
            String secretToken = result.data.getAuthToken().secret;

            Log.i(TAG, "Access Token:- " + accessToken);
            Log.i(TAG, "Secreat Token:- " + secretToken);
            // saving access tokens in sharedPReference
            saveTwitterToken(accessToken, secretToken, twitter_id);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.e(TAG,"Twitter Login Exception:- "+exception.toString());
        }
    });
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Pass the activity result to the login button.
        loginButton.onActivityResult(requestCode, resultCode, data);
    }

I don’t understand why i am getting this exception. Same code i am using for MainActivity but it’s working on MainActivity but not on configuration Activity.


#2