Search code examples
javaandroidfacebookfacebook-sdk-3.0

Permission for Facebook SDK


After that I press the 'Login to Facebook' button and login, it will crash. The problem is the permission for some stuff that I need to my app.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_social_login, container,
            false);
    LoginButton authButton = (LoginButton) view
            .findViewById(R.id.authButton);
    authButton.setFragment(this);
    authButton.setReadPermissions(Arrays.asList("name", "user_birthday",
            "friends_birthday"));

When I comment this line, everything will work nice.

authButton.setReadPermissions(Arrays.asList("name", "user_birthday", "friends_birthday"));

But when I delete the comment I will get this error.

11-18 13:16:03.983: D/FacebookSDK.WebDialog(2362): Redirect URL: fbconnect://success?error_code=100&error_message=Invalid+Scope%3A+name&e2e=%7B%22init%22%3A1384798557797%7D

Someone knows this error? Invalid Scope & name, something to do with the Graph API?

Thank you.


Solution

  • When you open up your app to edit settings on the Facebook developers site, there is side bar with permissions. Just type the ones you need in Extended Permissions. I know this is more of a work around, but its the best option with the minimal code you have provided.

    here is an example

    // set permission list
              authButton.setReadPermissions(Arrays.asList("basic_info","email"));
              // session state call back event
              authButton.setSessionStatusCallback(new Session.StatusCallback() {
    
               @SuppressWarnings("deprecation")
            @Override
               public void call(Session session, SessionState state, Exception exception) {
    
                if (session.isOpened()) {
                          Log.i(TAG,"Access Token"+ session.getAccessToken());
                          Request.executeMeRequestAsync(session,
                                  new Request.GraphUserCallback() {
                                      @Override
                                      public void onCompleted(GraphUser user,Response response) {
                                          if (user != null) { 
                                           Log.i(TAG,"User ID "+ user.getId());
                                           Log.i(TAG,"Email "+ user.asMap().get("email"));
                                           Log.i(TAG,"Name "+ user.asMap().get("name"));
                                           uName = user.asMap().get("name").toString();
                                           savePreferences();
                                           restorePreferences();
    
                                                                                          }
                                      }
                                  });
                      }
    
               }
              });