获取facebook个人资料专辑的图片

时间:2014-04-02 14:52:33

标签: android facebook facebook-graph-api facebook-fql fql.multiquery

谢谢你的时间和帮助。

我正在尝试获取当前用户的所有个人资料照片,但我得到了一个奇怪的答案:

{Response: responseCode:200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache: false}

我已经进行了身份验证并成功加载了其他一些信息。

我已经检查了一些其他类似的问题/答案,我没有找到任何人使用fql和facebook的新API。

权限定义如下:

/**
 * the list of permissions of facebook
 * */
private static final List<String> FACEBOOK_PERMISSION_LIST = Arrays.asList(
        "user_photos", "email", "user_birthday", "basic_info");

代码

String fqlQuery = "SELECT src_big FROM photo WHERE album_object_id IN (SELECT object_id  FROM album WHERE owner = me() AND name='Profile Pictrue' AND type='profile' )";
Bundle params = new Bundle();
params.putString("q", fqlQuery);

Session session = Session.getActiveSession();
Request request = new Request(session, "/fql",
                        params, HttpMethod.GET,
                        new Request.Callback() {
                                public void onCompleted(
                                    Response response) {
                                        Log.i(TAG, "Got results: "
                                                + response.toString());
                                    }
                                });
                        Request.executeBatchAsync(request);

我希望你能帮助我,欢迎每一个建议。

1 个答案:

答案 0 :(得分:1)

name='Profile Pictrue'中有一个拼写错误;它是name='Profile Pictures'

(但问题是你不需要检查这个nametype=profile就够了。)

所以你的最终查询应该是:

SELECT src_big
FROM photo
WHERE album_object_id IN (
    SELECT object_id 
    FROM album
    WHERE owner = me() 
    AND type='profile'
)

或更好(因为我无法按类型查询):

String fqlQuery = "SELECT src_big FROM photo WHERE album_object_id IN (SELECT object_id  FROM album WHERE owner = me()  AND (type='profile' OR name='Profile Pictures'))";

在请求中添加一些参数,如下所示:

Bundle params = new Bundle();
params.putString("q", fqlQuery);
params.putString("format", "json");
params.putString("query", fqlQuery);
params.putString("access_token", fbAccessToken);
Session session = Session.getActiveSession();
Request request = new Request(session, "/fql", params, HttpMethod.GET, new Request.Callback() {
    public void onCompleted(Response response) {
        Log.i(TAG, "Got results: " + response.toString());
    }
});
Request.executeBatchAsync(request);