I have a problem and I dont know why, I hope you could help me!
I am developing an android app which uses the facebook graph api. It uses the readpermission "user_likes". When i do this request: "me/likes" everything works fine. But when i do this: me/likes?fields=events{cover},name
I get an OAuthException. errorMessage: An active access token must be used to query information about the current user
In conclusion:
- I get a valid access token with all required permissions.
- I am the administrator of my app so facebook privacy policy should not play any role!
- Request
me/likes
works, but
me/likes?fields=events
does not work!
Response I get:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}, isFromCache:false}
So I debuged my Access-Token:
Issued: 1420803216 (4 hours ago)
Expires: 1425987216 (in about 2 months)
Valid: True
Origin: Mobile Web Faceweb
Scopes: public_profile, basic_info, email, user_birthday, user_location, user_likes, user_friends
I do not realy understand why my access token has so many scopes? I just set "user_likes"!
loginBtn.setReadPermissions(Arrays.asList("user_likes"));
This is my Code:
private LoginButton loginBtn;
private TextView username;
private UiLifecycleHelper uiHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (TextView) findViewById(R.id.username);
loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
loginBtn.setReadPermissions(Arrays.asList("user_likes"));
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
username.setText("You are currently logged in as "
+ user.getName());
} else {
username.setText("You are not logged in.");
}
}
});
}
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
public void call(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.d("MainActivity", "Facebook session opened.");
} else if (state.isClosed()) {
Log.d("MainActivity", "Facebook session closed.");
}
}
};
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
private void onSessionStateChange(final Session session,
SessionState state, Exception exception) {
if (state.isOpened()) {
// userInfoTextView.setVisibility(View.VISIBLE);
String token = session.getAccessToken();
Log.d("SESSION_TOKEN", token);
new Request(session, "me/likes?fields=events", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
Log.i("INFO", response.toString());
// new
// GetResponses(userInfoTextView).execute(response);
}
}).executeAsync();
} else if (state.isClosed()) {
// userInfoTextView.setVisibility(View.INVISIBLE);
}
}
What are I am doing wrong? I guess something with my session or permission request is wrong...i hope someone can help me!
kind regards christoph