I am trying to integrate Facebook login with my Android app. As I click on 
the login button, it launches Facebook login page then another window "your 
have already authorized myapp". Here, as I click on OK, it takes me back to 
my app's last view and nothing is happening and it's not getting any 
callback of Loginmanager.

I am referring to this link 
*https://developers.facebook.com/docs/facebook-login/android* 
<https://developers.facebook.com/docs/facebook-login/android> and following 
all the steps like

Generate development key, App id , update build.gradle file, manifeast 
file, etc.
Enter code public class MyFBFragment extends BaseFragment {

    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    final String TAG = "MyFBFragment ";
    private static  int count = 0;

    private final List<String> permissions;
    private CallbackManager mCallbackManager;
    private ProfileTracker mProfileTracker;
    public static MyFBFragment fragment;

    public MyFBFragment () {
        // Required empty public constructor
        permissions = Arrays.asList("user_status","public_profile", 
"user_friends");
    }

       public static MyFBFragment getInstance(String param1, String param2) 
{

        if(count == 0) {
             fragment = new MyFBFragment ();
            Bundle args = new Bundle();
            args.putString(ARG_PARAM1, param1);
            args.putString(ARG_PARAM2, param2);
            fragment.setArguments(args);
            count++;
        }
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

        Boolean fbDebugFlag = true;

        FacebookSdk.sdkInitialize(getActivity());
        FacebookSdk.setIsDebugEnabled(fbDebugFlag);//to do " only for debug 
app
        mCallbackManager = CallbackManager.Factory.create();
        LoginManager.getInstance().registerCallback(mCallbackManager,
                new FacebookCallback<LoginResult>() {

                    @Override
                    public void onSuccess(LoginResult loginResult) {
                        Toast.makeText(getActivity(), "onSuccess", Toast.
LENGTH_LONG).show();
                        // App code
                        Profile currentProfile = Profile.getCurrentProfile
();
                       
                        Logger.debug(TAG, "***********loginResponse: " + 
currentProfile.getFirstName());

                        GraphRequest request = GraphRequest.newMeRequest(
                                loginResult.getAccessToken(),
                                new GraphRequest.GraphJSONObjectCallback() {
                                    @Override
                                    public void onCompleted(
                                            JSONObject object,
                                            GraphResponse response) {
                                        // Application code
                                        Log.v("LoginActivity", response.
toString());

                                                                            
}
                                });
                        Bundle parameters = new Bundle();
                        parameters.putString("fields", "id,name,email,gender, 
birthday");
                        request.setParameters(parameters);
                        request.executeAsync();

                    }

                    @Override
                    public void onCancel() {
                        // App code
                        Logger.debug(TAG, "***********Cancel: " + 
currentProfile.getFirstName());
                    }

                    @Override
                    public void onError(FacebookException exception) {
                        // App code
                        Logger.debug(TAG, "***********OnError: " + 
currentProfile.getFirstName());                    }
                });

                };


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
Bundle savedInstanceState) {
        if (container == null) {
            return null;
        }
        View view = inflater.inflate(R.layout.fragment_myaccount, container, 
false);
       TextView fbLogin = (TextView) view.findViewById(R.id.facebook);


        fbLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginManager.getInstance().logInWithReadPermissions(
MyAccountFragment.this, permissions);

            }
        });

        return view ;
    }

    @Override
     public void onActivityResult(final int requestCode, final int 
resultCode, final Intent data) {

        Toast.makeText(getActivity(), "onActivityResult", Toast.LENGTH_LONG
).show();
       // super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mProfileTracker.stopTracking();
    }
}here...


I have tried all the



I am aware of the fact that if use Fragment then OnActivityResult will be 
called of Activity then direct this to Fragment's OnActivityResult. So I am 
getting the Fragment's OnActivity result but not Loginmanager call back.


requestCode: 129742 resultCode: -1  during debugI have checked mCallbackManager 
is not null.


Please help me as I am completely clueless here.



-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/9f4b9fd2-3b81-4c33-9096-7a4b2f591c15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to