2

我使用适用于 Android 3.0 的 Facebook SDK 我想获取用户的照片并在我的应用程序中显示。参考文档,登录成功。我试着拿到这张专辑。

我尝试了两种方法fqlgraph api

    graph_or_fql = "fql";
    if (graph_or_fql.equals("fql")) {
        String query = "SELECT aid, cover_pid, name, size, visible, object_id FROM album WHERE owner = "
                + userId;
        Bundle params = new Bundle();
        params.putString("method", "fql.query");
        params.putString("query", query);

        mAsyncRunner.request(null, params,
                new PhotosRequestListener());
    } else {
//      Bundle params = new Bundle();
//      params.putString("fields", "name, aid, size");
//      mAsyncRunner.request("me/photos", params,
//              new PhotosRequestListener());
        mAsyncRunner.request("me/album",
                new PhotosRequestListener());
    }

    /*
     * callback after friends are fetched via me/friends or fql query.
     */
    public class PhotosRequestListener extends BaseRequestListener {

        @Override
        public void onComplete(final String response, final Object state) {
            dialog.dismiss();
            Log.d("tag", "response: " + response);
            try {
                if (graph_or_fql.equals("fql")) {
                    jsonArray = new JSONObject(response).getJSONArray("data");
                    // jsonArray = new JSONArray(response);
                    // JSONObject jsonObj = new JSONObject(response);
                    // jsonArray = new JSONArray(jsonObj.getString("data"));
                } else {
                    jsonArray = new JSONObject(response).getJSONArray("data");
                }
            } catch (JSONException e) {
                showToast("JSONError: " + e.getMessage());
                e.printStackTrace();
                return;
            }
            gridView.setOnItemClickListener(MainActivity.this);
            gridView.setAdapter(new GridViewAdapter(MainActivity.this));
        }

        public void onFacebookError(FacebookError error) {
            dialog.dismiss();
            Toast.makeText(getApplicationContext(),
                    "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }
    }

但全是错误。

fql 错误消息:“error_msg”:“会话密钥无效或不再有效”

11-07 16:41:10.956: D/tag(468): response: {"error_code":102,"error_msg":"Session key invalid or no longer valid","request_args":[{"key":"query","value":"SELECT aid, cover_pid, name, size, visible, object_id FROM album WHERE owner = 100001791736733"},{"key":"method","value":"fql.query"},{"key":"format","value":"json"}]}
11-07 16:41:10.956: W/System.err(468): org.json.JSONException: No value for data
11-07 16:41:10.966: W/System.err(468):  at org.json.JSONObject.get(JSONObject.java:354)
11-07 16:41:11.015: W/System.err(468):  at org.json.JSONObject.getJSONArray(JSONObject.java:544)
11-07 16:41:11.015: W/System.err(468):  at com.example.facebookphoto.MainActivity$PhotosRequestListener.onComplete(MainActivity.java:144)
11-07 16:41:11.015: W/System.err(468):  at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:273)

graph api 错误消息:“error”:{“message”:“必须使用活动访问令牌来查询当前用户的信息。”“type”:“OAuthException”“code”:2500}

11-07 16:45:43.106: D/tag(538): response: {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
11-07 16:45:43.106: W/System.err(538): org.json.JSONException: No value for data
11-07 16:45:43.156: W/System.err(538):  at org.json.JSONObject.get(JSONObject.java:354)
11-07 16:45:43.156: W/System.err(538):  at org.json.JSONObject.getJSONArray(JSONObject.java:544)
11-07 16:45:43.176: W/System.err(538):  at com.example.facebookphoto.MainActivity$PhotosRequestListener.onComplete(MainActivity.java:149)
11-07 16:45:43.176: W/System.err(538):  at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:273)

我不明白,因为什么原因。帮帮我,谢谢。

4

0 回答 0