Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric Log in with twitter button is greyed out

I followed the instructions using Fabric to implement my sign in in my custom app.

The problem is that when i run my app the button is greyed out.

Here are the errors on my stack trace:

03-20 11:06:32.456    6509-6509/com.jan.simplesharing E/Twitter﹕ Must Initialize Fabric before using singleton()

03-20 11:06:32.546    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 46
03-20 11:06:32.556    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 49
03-20 11:06:32.556    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50
03-20 11:06:32.556    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50
03-20 11:06:32.556    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50
03-20 11:06:32.566    6509-6509/com.jan.simplesharing E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 52

But i also initialized fabric in my activity.

Here's a snippet:

import io.fabric.sdk.android.Fabric;

import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
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;

public class MainActivity extends Activity {

//copied key and secret from fabric
private static final String TWITTER_KEY = "my key here"; 
private static final String TWITTER_SECRET = "my secret here";

private TwitterLoginButton loginButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /* Twitter */
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));

    loginButton = (TwitterLoginButton) findViewById(R.id.twitter_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
        }

        @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);

    /* Twitter */
    loginButton.onActivityResult(requestCode, resultCode, data);
}
like image 791
Jan Avatar asked Mar 20 '15 03:03

Jan


2 Answers

setContentView(R.layout.activity_main);

/* Twitter */
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));

You have to initialize Fabric before inflating the Twitter button. Because otherwise when Twitter button constructor is called it doesn't know how to connect twitter api. This is what the error description says in a nutshell.

6509-6509/com.jan.simplesharing E/Twitter﹕ Must Initialize Fabric before using singleton()

In general, you can initialize Fabric at the Application class. This is what they do at their sample showcase app: https://github.com/twitterdev/cannonball-android/blob/master/app/src/main/java/io/fabric/samples/cannonball/App.java#L98

like image 181
Sergii Pechenizkyi Avatar answered Nov 03 '22 10:11

Sergii Pechenizkyi


Follow these steps to achieve twitter login using Fabric :

Create a class which extends Application class and copy the following code into it -

TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));

Fabric.with() performs the functionality of initializing. Do no forget to mention this application class in your android manifest file

 <application
    android:name="com.demoapp.BaseApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:theme="@android:style/Theme.Black" >
like image 23
XylemRaj Avatar answered Nov 03 '22 10:11

XylemRaj