我是 facebook SDK 的新手,我遇到了这个问题:登录后我有 Session对象,我想执行一些图形 API 请求。这是我的代码:
Request request = new Request(session, "me?fields=email,installed,first_name,last_name");
Response response = request.executeAndWait();
GraphObject obj = response.getGraphObject();
JSONObject json = obj.getInnerJSONObject();
这是Request对象(toString()
):
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, email, contact_email, user_hometown]}, appId:MY_APP_ID}, graphPath: me?fields=email,installed,first_name,last_name, graphObject: null, restMethod: null, httpMethod: GET, parameters: Bundle[{access_token=ACCESS_TOKEN_STRING_OF_SESSION, format=json, sdk=android}]}
这是Response对象(toString()
):
{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}
当我在浏览器中执行请求时,如下所示:
https://graph.facebook.com/v2.0/me?access_token=ACCESS_TOKEN_STRING_OF_SESSION
我收到了有效的 json 响应。
所以我收到了这个错误,如响应中所示,这是为什么? Request 对象似乎一切正常。
谢谢
最佳答案
好的,这是对我有用的解决方案:
Bundle bundle = new Bundle();
bundle.putString("fields", "email,installed,first_name,last_name");
Request request = new Request(session, "me", bundle, HttpMethod.GET);
Response response = request.executeAndWait();
GraphObject obj = response.getGraphObject();
JSONObject json = obj.getInnerJSONObject();
我没有找到任何有关此类 API 调用的文档。
关于java - Facebook android SDK 图形请求 - 访问 token 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23524016/