Login button: Not passing to success after onActivityResult() in fragment

android
login

#1

Hi every,
I’ve got a problem, I’ve implmented the Twitter LoginButton with Fabric.

I’ve implemented the button in a android fragment :

Tab1.java

package fr.hidevs.radiomedfrance.fragments;
//some code here//
import android.content.Intent;
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 de.hdodenhof.circleimageview.CircleImageView;
import fr.hidevs.radiomedfrance.R;

public class Tab1 extends Fragment {
    private static TwitterLoginButton loginButton;
    private static CircleImageView circleImageView ;
    private static TextView mTextDetails, mUsername,mAccountType;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.tab_1, container, false);
    circleImageView = (CircleImageView)rootView.findViewById(R.id.circleView);
    return rootView;

}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    setupTextDetails(view);
    setupLoginButton(view);
}


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

}

private void setupTextDetails(View view) {
    mTextDetails = (TextView) view.findViewById(R.id.text_details);
    mUsername = (TextView) view.findViewById(R.id.name);
    mAccountType = (TextView) view.findViewById(R.id.email);
}

private void setupLoginButton(View view) {
    loginButton = (TwitterLoginButton) view.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
            String output = "Status: " +
                    "Your login was successful " +
                    result.data.getUserName() +
                    "\nAuth Token Received: " +
                    result.data.getAuthToken().token;

            mTextDetails.setText(output);
        }

        @Override
        public void failure(TwitterException exception) {
            // Do something on failure
            exception.toString();
            mTextDetails.setText("Status: Login Failed  :  "+exception.toString());
        }
    });
    }
}

This the code for my MainActivity :

package fr.hidevs.radiomedfrance;
//some code here//
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;


public class MainActivity extends ActionBarActivity  {
   //some code here//
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        android.app.Fragment fragment = getFragmentManager()
                .findFragmentById(R.id.tab1);
        if (fragment != null) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }
}

and this is my AppController :

package fr.hidevs.radiomedfrance.app;


import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import io.fabric.sdk.android.Fabric;


public class AppController extends Application {


   private static final String TWITTER_KEY = "MY_KEY";
    
   private static final String TWITTER_SECRET="MY_SECRET";

    @Override
    public void onCreate() {
        super.onCreate();
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));
        
    }
//some code here//
}

And I’ve got this message :

E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.

Can you help me ?


#2