Question

I want to create a facebook login button for my application.

My problem is, that I want to call 'authorize' with an OnClickListener, but eclipse marks the 'authorize' part as an error. It suggests to replace it with authorizeCallback, but it's not the solution.

It seems like I'm just missing something, but don't know what. Any idea please?

This is where the error occurs (facebook.authorize):

LoginButton.setOnClickListener(new OnClickListener() 
{
         public void onClick(View v) 
         {
         facebook.authorize(this, new String[] { "email", "user_birthday" }, new FacebookLoginDialogListener());    
          }});
    }

Rest of the code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
        super.onActivityResult(requestCode, resultCode, data);
        facebook.authorizeCallback(requestCode, resultCode, data);
}

public class FacebookLoginDialogListener implements DialogListener  
    {
        public void onComplete(Bundle values) {
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putString("access_token", facebook.getAccessToken());
            editor.putLong("access_expires", facebook.getAccessExpires());
            editor.commit();
            requestUserData(); 
        }

        public void onFacebookError(FacebookError error) {}

        public void onError(DialogError e) {}

        public void onCancel() {}

    }
Was it helpful?

Solution

do this way:

facebook.authorize(YourActivity.this, new String[] { "email", "user_birthday" }, new FacebookLoginDialogListener());

You are passing OnClickListener's this reference to the method, You have to pass Activity's Context to the method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top