I am trying to setup twitter login in android studio with fabric. Everything builds nicely without any errors.
When I try running the application on my phone and press the twitter login button, it goes to a white screen and shows a progress bar and then it closes and goes back to the screen with the twitter button. It doesn't crash the app, it only gives me an error.
I've followed twitters developer documentation perfectly. This is the error i'm getting
01-25 16:58:59.359 32491-32491/com.myegotest.ego_17012016 E/Twitter: SSO auth activity not found
01-25 16:58:59.369 827-1358/? E/Parcel: Class not found when unmarshalling: com.twitter.sdk.android.core.TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel: java.lang.ClassNotFoundException: com.twitter.sdk.android.core.TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel: Caused by: java.lang.NoClassDefFoundError: com/twitter/sdk/android/core/TwitterAuthConfig
01-25 16:58:59.369 827-1358/? E/Parcel: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.twitter.sdk.android.core.TwitterAuthConfig" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: Invalid json: <?xml version="1.0" encoding="UTF-8"?>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: <hash>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: <error>Desktop applications only support the oauth_callback value 'oob'</error>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: <request>/oauth/request_token</request>
01-25 16:59:00.399 32491-32491/com.myegotest.ego_17012016 E/Twitter: </hash>
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: Failed to get request token
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: com.twitter.sdk.android.core.TwitterApiException: 401 Authorization Required
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.Platform$Android$2$1.run(Platform.java:142)
01-25 16:59:00.419 32491-32491/com.myegotest.ego_17012016 E/Twitter: at java.lang.Thread.run(Thread.java:841)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: Authorization completed with an error
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:215)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at android.os.Handler.handleCallback(Handler.java:733)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at android.os.Handler.dispatchMessage(Handler.java:95)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at android.os.Looper.loop(Looper.java:157)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at android.app.ActivityThread.main(ActivityThread.java:5293)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at java.lang.reflect.Method.invokeNative(Native Method)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at java.lang.reflect.Method.invoke(Method.java:515)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-25 16:59:00.799 32491-32491/com.myegotest.ego_17012016 E/Twitter: at dalvik.system.NativeStart.main(Native Method)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: Login with Twitter failure
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:215)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at com.twitter.sdk.android.core.Callback.failure(Callback.java:45)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at android.os.Handler.handleCallback(Handler.java:733)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at android.os.Handler.dispatchMessage(Handler.java:95)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at android.os.Looper.loop(Looper.java:157)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at android.app.ActivityThread.main(ActivityThread.java:5293)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at java.lang.reflect.Method.invokeNative(Native Method)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at java.lang.reflect.Method.invoke(Method.java:515)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-25 16:59:00.829 32491-32491/com.myegotest.ego_17012016 D/TwitterKit: at dalvik.system.NativeStart.main(Native Method)
Here is my activity code
package com.myegotest.ego_17012016;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterLoginButton;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import io.fabric.sdk.android.Fabric;
public class SocialNetworkSelector_setupPage2 extends Activity {
private static final String TWITTER_KEY = "key here";
private static final String TWITTER_SECRET = "key here";
private TwitterLoginButton twitterLoginButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));
setContentView(R.layout.activity_social_network_selector_setup_page2);
twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
twitterLoginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// The TwitterSession is also available through:
Twitter.getInstance().core.getSessionManager().getActiveSession();
TwitterSession session = result.data;
String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
@Override
public void failure(TwitterException exception) {
Log.d("TwitterKit", "Login with Twitter failure", exception);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
twitterLoginButton.onActivityResult(requestCode, resultCode, data);
}
}
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myegotest.ego_17012016">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-sdk tools:overrideLibrary="com.facebook"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<activity
android:name=".LoginActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter android:autoVerify="true" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.myegotest.com" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register"
android:parentActivityName=".LoginActivity"
android:theme="@style/AppTheme.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".LoginActivity" />
</activity>
<activity android:name=".HomeActivity" >
</activity>
<activity
android:name=".AccountConfirmationActivity"
android:label="@string/title_activity_account_confirmation"
android:parentActivityName=".LoginActivity"
android:theme="@style/AppTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".LoginActivity" />
</activity>
<activity android:name=".ForgotPassword" >
</activity>
<activity
android:name=".ResetPassword"
android:label="@string/title_activity_reset_password"
android:theme="@style/AppTheme" >
</activity>
<activity
android:name=".LetGetStarted_setupPage4"
android:label="@string/title_activity_let_get_started"
android:theme="@style/AppTheme" >
</activity>
<activity android:name=".UploadPhoto_setupPage3" >
</activity>
<activity android:name=".ImageListView" >
</activity>
<activity android:name=".ViewFullImage" >
</activity>
<activity android:name=".SocialNetworkSelector_setupPage2" >
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="key here" />
</application>
</manifest>
Here is my build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myegotest.ego_17012016"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.facebook.android:facebook-android-sdk:4.9.0'
compile('com.twitter.sdk.android:twitter:1.12.0@aar') {
transitive = true;
}
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
You need to set a callback URL in the Twitter App Settings. It actually doesn't matter what you set it to, it will be replaced automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With