Java – Permission error – Try to make friends using the android Facebook SDK

Permission error – Try to make friends using the android Facebook SDK… here is a solution to the problem.

Permission error – Try to make friends using the android Facebook SDK

I’m trying to add a feature to my Android app that allows users to “check in” with others who are marked as check-in.
I have no problem with the checkins method, I can mark a method by adding the user ID as a parameter (see the code below).

public void postLocationTagged(String msg, String tags, String placeID, Double lat, Double lon) {
    Log.d("Tests", "Testing graph API location post");
    String access_token = sharedPrefs.getString("access_token", "x");
     try {
         if (isSession()) {
            String response = mFacebook.request("me");
            Bundle parameters = new Bundle();
            parameters.putString("access_token", access_token);
            parameters.putString("place", placeID);
            parameters.putString("Message",msg);
            JSONObject coordinates = new JSONObject();
            coordinates.put("latitude", lat);
            coordinates.put("longitude", lon);
            parameters.putString("coordinates",coordinates.toString());
            parameters.putString("tags", tags);
            response = mFacebook.request("me/checkins", parameters, "POST");
            Toast display = Toast.makeText(this, "Checkin has been posted to Facebook.", Toast.LENGTH_SHORT);
            display.show();
            Log.d("Tests", "got response: " + response);
            if (response == null || response.equals("") || 
                    response.equals("false")) {
               Log.v("Error", "Blank response");
            }
        } else {
          no logged in, so relogin
         Log.d(TAG, "sessionNOTValid, relogin");
         mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
     } catch(Exception e) {
         e.printStackTrace();
     }
}

This works fine (I’ve posted it in case it helps anyone else!), and the problem I’m having is that I’m trying to create a list of user friends so they can choose the friend tag they want. I have the method getFriends (see below), and then I’ll use it to generate an AlertDialog that the user can choose from, which will then give me the id I used in the “postLocationTagged” method above.

public void getFriends(CharSequence[] charFriendsNames,CharSequence[] charFriendsID, ProgressBar progbar) {
    pb = progbar;
    try {
        if (isSession()) {
            String access_token = sharedPrefs.getString("access_token", "x");
            friends = charFriendsNames;
            friendsID = charFriendsID;
           Log.d(TAG, "Getting Friends!");
           String response = mFacebook.request("me");
           Bundle parameters = new Bundle();
           parameters.putString("access_token", access_token);
           response = mFacebook.request("me/friends", parameters, "POST");

Log.d("Tests", "got response: " + response);
           if (response == null || response.equals("") || 
                   response.equals("false")) {
              Log.v("Error", "Blank response");
           }

} else {
         no logged in, so relogin
        Log.d(TAG, "sessionNOTValid, relogin");
        mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}

When I look at the response in the log, it shows:

“Get Response: {“Error”:

{“Type”: “OAuthException”, “Message”: “(#200) Permission Error ‘}}’

I looked at the graphAPI documentation and searched for similar issues, but to no avail! I’m not sure if I need to request additional permissions for the app, or if it’s something you’re not allowed to do! Any help/advice would be appreciated.

Solution

You may need the following permissions:

  • user_checkins
  • friends_checkins
  • Read your friends list
  • Manage your friends list
  • publish_checkins

Check out the API documentation. Before doing so, determine which line is causing the permission error and try to fix it.

Related Problems and Solutions