问题
I have integrated Facebook login in my app, but when trying to get the name out of the basic info of the logged in user, 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
}
I logged my session token and its expiration date and it is not null nor expired. I tried replacing session with getActiveSession() but that didn't fix anything.
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
final SharedPreferences prefs = getActivity().getSharedPreferences(
"fbInfo", Context.MODE_PRIVATE);
if (session != null && session.getState().isOpened()){
Log.i("sessionToken", session.getAccessToken());
Log.i("sessionTokenDueDate", session.getExpirationDate().toLocaleString());
}
new Request(session, "/me?fields=name", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
try {
prefs.edit().putString("name", graphResponse.getString("name")).commit();
} catch (JSONException e) {
Log.i(TAG,
"JSON error " + e.getMessage());
}
}
}
).executeAsync();
new Request(session, "/me?fields=quotes", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
try {
prefs.edit().putString("quotes", graphResponse.getString("quotes")).commit();
} catch (JSONException e) {
Log.i(TAG,
"JSON error " + e.getMessage());
}
}
}
).executeAsync();}
回答1:
Try this
if (state.isOpened())
{
Log.i("Facebook", "Logged in...");
new Request(session, "me/photos",getRequestParameters(), null, new Callback()
{
@Override
public void onCompleted(Response response)
{
}
}).executeAsync();
....
private Bundle getRequestParameters()
{
Bundle parameters = new Bundle(1);
parameters.putString("fields", "images,other");
return parameters;
}
回答2:
Am i implementing 4.6.0 FacebookSDK and phasing these error but after manage proper structure of classes got success..!!
AccessToken Class object's initialize after GraphRequest class & inside GraphRequest use object of AccessToken
AccessToken accessToken = AccessToken.getCurrentAccessToken();
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Application code
System.out.println("object>>" + object);
System.out.println("response>>" + response.toString());
}
});
来源:https://stackoverflow.com/questions/21610689/android-app-using-facebook-login-an-active-access-token-must-be-used-to-query-i