Android 和 Facebook:如何在 Android 应用程序中使用 Facebook 查询语言 (FQL)

发布于 2024-10-07 18:51:00 字数 303 浏览 0 评论 0原文

在此页面上,Facebook 告诉您,您可以以某种方式使用 Facebook 查询语言: http: //developers.facebook.com/docs/reference/fql/profile

但我只是不明白查询是什么样的。在 Stackoverflow 上,我只是找到有关如何将 FQL 与 PHP 结合使用的示例。但我想在 Android 应用程序之外使用它。谁能给我网址或代码示例?

On this page facebook tells you, that you can somehow use the Facebook-Query-Language: http://developers.facebook.com/docs/reference/fql/profile

But I just dont understand what the query looks like. On Stackoverflow I just find exapmles on how to use the FQL with PHP. But I want to use it out of and Android Application. Anybody can give me URLs or Code Examples?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜访吸血鬼 2024-10-14 18:51:00

使用 Facebook Android SDK,可以像这样实现 FQL 调用:

 String query = "SELECT name FROM user WHERE uid = me()";
 Bundle params = new Bundle();
 params.putString("method", "fql.query");
 params.putString("query", query);
 mAsyncFacebookRunner.request(null, params, new FQLRequestListener());

其中 FQLRequestListener 扩展了 RequestListener ,就像 Graph 调用一样。

Using the Facebook Android SDK, an FQL call can be implemented like this:

 String query = "SELECT name FROM user WHERE uid = me()";
 Bundle params = new Bundle();
 params.putString("method", "fql.query");
 params.putString("query", query);
 mAsyncFacebookRunner.request(null, params, new FQLRequestListener());

where FQLRequestListener extends RequestListener, just as for a Graph call.

如歌彻婉言 2024-10-14 18:51:00

请参阅此链接 https://developers.facebook.com/docs/reference/fql ,您可以更深入,因为您可以单击每个元素并查看每个元素的所有属性(例如此处的“相册”:https://developers.facebook.com/docs/reference/fql/album/ )。

这是一个通过“album_id”获取相册图片的 url 的查询示例:

String fqlQuery = "SELECT src FROM photo WHERE album_object_id="+ <your_album_id>;

这是调用您的请求的方法之一:

                            Bundle params = new Bundle();                               
                            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);

我希望我有所帮助,祝你好运! :)

See this link https://developers.facebook.com/docs/reference/fql , and you can go deeper because you can click on each element and see all the propreties of each element , ( exemple "album" here : https://developers.facebook.com/docs/reference/fql/album/ ).

This is an exemple of query to get the url of the pictures of an album by "album_id" :

String fqlQuery = "SELECT src FROM photo WHERE album_object_id="+ <your_album_id>;

This is one of the ways to call your request :

                            Bundle params = new Bundle();                               
                            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);

I hope I helped, good luck! :)

面如桃花 2024-10-14 18:51:00

如果我将其放入浏览器中,这似乎可以工作,但我不知道如何告诉 Android Facebook SDK 使用此查询:
https://api.facebook.com/method/fql.query?query=select+pic_small+from+profile+where+id+%3D+USERID;&access_token=ACCESSTOKEN

This seems to work if I put it into the Browser, but I dont know how to tell the Android Facebook SDK to use this query:
https://api.facebook.com/method/fql.query?query=select+pic_small+from+profile+where+id+%3D+USERID;&access_token=ACCESSTOKEN

韶华倾负 2024-10-14 18:51:00

我还没有尝试过,但是对于调用 fql 你可以尝试

public String request(String fql)  throws FileNotFoundException, MalformedURLException, IOException {
Bundle parameters = new Bundle
parameters.putString("format", "json");
parameters.putString("query", fql);
parameters.putString("access_token",  mFacebook.getAccessToken());

if (mFacebook.isSessionValid()) {
    params.putString("access_token", mFacebook.getAccessToken());
}
        String url = (fql != null) ? "https://api.facebook.com/method/fql.query" : "https://api.facebook.com/restserver.php";
return Util.openUrl(url, "GET", params);
}

它应该可以工作。

您必须考虑到 mFacebook 是经过身份验证的 Facebook 对象(属于 Facebook Android SDK)。另外,fql 应该使用 url 支持的格式填充。例如:

select+pic_small+from+profile+where+id+%3D+USERID;

代替

select pic_small from profile where id=USERID;

I haven't tried it, but for calling fql you can try

public String request(String fql)  throws FileNotFoundException, MalformedURLException, IOException {
Bundle parameters = new Bundle
parameters.putString("format", "json");
parameters.putString("query", fql);
parameters.putString("access_token",  mFacebook.getAccessToken());

if (mFacebook.isSessionValid()) {
    params.putString("access_token", mFacebook.getAccessToken());
}
        String url = (fql != null) ? "https://api.facebook.com/method/fql.query" : "https://api.facebook.com/restserver.php";
return Util.openUrl(url, "GET", params);
}

It should work.

You have to take into acount that mFacebook is an authenticated Facebook Object (of the Facebook Android SDK). Also, that the fql sould be filled with a format supported by an url. For example:

select+pic_small+from+profile+where+id+%3D+USERID;

instead of

select pic_small from profile where id=USERID;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文