获取Facebook好友访问令牌错误?

时间:2014-08-09 11:32:31

标签: android facebook-graph-api

我正在使用此代码来获取facbook朋友,但它给了我错误 {"错误":{"消息":"必须使用活动访问令牌来查询有关当前用户的信息。","键入&# 34;:" OAuthException"," code":2500}}

请让我知道我做错了什么

这是我的代码:

    parameters.putString("format", "json");

    parameters.putString("token", args[0]);

    String url = "https://graph.facebook.com/me/friends";

    String response = Util.openUrl(url, "GET", parameters);

    JSONObject obj = Util.parseJson(response);

    Log.i("json Response", obj.toString());

    JSONArray array = obj.optJSONArray("data");
    return null;

1 个答案:

答案 0 :(得分:0)

我使用此方法是为了让Facebook朋友在他们的设备上安装应用程序,但使用fql,您可以编写自己的查询来满足您的需求。

这样的事情应该这样做。

 Session session = Session.getActiveSession();
    session.getAccessToken();

    String fqlQuery = "SELECT uid, name, pic_big FROM user WHERE is_app_user  " +
            "AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

    Bundle params = new Bundle();
    params.putString("q", fqlQuery);

    Request request = new Request(session,
            "/fql",
            params,
            HttpMethod.GET,
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {

                    GraphObject graphObject = response.getGraphObject();

                    if (graphObject != null) {

                        if (graphObject.getProperty("data") != null) {
                            try {

                                JSONArray jArray =
                                        new JSONArray(graphObject.getProperty("data").toString());

                                for (int i = 0; i < jArray.length(); i++) {

                                    JSONObject jObject = jArray.getJSONObject(i);
                                }

                            } catch (Exception e) {

                            }
                        }
                    }
                }
            }
    );
    request.executeAsync();