使用 facebook android SDK 的 FQL

发布于 2024-09-19 23:34:02 字数 455 浏览 10 评论 0原文

我正在尝试使用 facebook android SDK 创建一个 android 应用程序 (http://github.com /facebook/facebook-android-sdk)。我试图弄清楚我是否能够使用此 SDK 来使用 FQL。如果有人有这方面的经验,请告诉我。

显然可以使用 https://api.facebook.com/method/ 来使用 FQL fql.query?query=QUERY,但是 facebook android SDK 似乎不支持这一点。

谢谢;

I'm trying to create an android application using the facebook android SDK (http://github.com/facebook/facebook-android-sdk). I'm trying to figure out if I will be able to use FQL using this SDK. If anyone has any experiences in this regard, please let me know.

FQL can apparently be used using https://api.facebook.com/method/fql.query?query=QUERY, the facebook android SDK however doesn't seem to support this.

Thanks;

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

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

发布评论

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

评论(4

冷心人i 2024-09-26 23:34:02

这可能是比提到的更好的方法。使用当前版本的 API,您无需手动添加访问令牌或使用 Util.openURL。

        Bundle params = new Bundle();
        params.putString("method", "fql.query");
        params.putString("query", "SELECT name, uid, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY name");
        String response = $fb.request(params);
        response = "{\"data\":" + response + "}";

        JSONObject json = Util.parseJson( response );
        JSONArray data = json.getJSONArray( "data" );

        for ( int i = 0, size = data.length(); i < size; i++ ){
            JSONObject friend = data.getJSONObject( i );

            String id = friend.getString( "uid" );
            String name = friend.getString( "name" );
            ...
        }

This is probably a better way than mentioned. Using the current version of the API you don't need to manually add the access token or use Util.openURL.

        Bundle params = new Bundle();
        params.putString("method", "fql.query");
        params.putString("query", "SELECT name, uid, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY name");
        String response = $fb.request(params);
        response = "{\"data\":" + response + "}";

        JSONObject json = Util.parseJson( response );
        JSONArray data = json.getJSONArray( "data" );

        for ( int i = 0, size = data.length(); i < size; i++ ){
            JSONObject friend = data.getJSONObject( i );

            String id = friend.getString( "uid" );
            String name = friend.getString( "name" );
            ...
        }
活雷疯 2024-09-26 23:34:02

以下是使用建议补丁的一些示例代码:

    Bundle b = new Bundle();
    b.putString("access_token", facebookManager.mFacebook.getAccessToken());
    b.putString("query", "SELECT name FROM user WHERE uid = me()");

    try {
        String myResult = Util.openUrl("https://api.facebook.com/method/fql.query", "GET", b);
            Log.i("MyResult", myResult);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Here is some sample code using the suggested patch:

    Bundle b = new Bundle();
    b.putString("access_token", facebookManager.mFacebook.getAccessToken());
    b.putString("query", "SELECT name FROM user WHERE uid = me()");

    try {
        String myResult = Util.openUrl("https://api.facebook.com/method/fql.query", "GET", b);
            Log.i("MyResult", myResult);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
っ〆星空下的拥抱 2024-09-26 23:34:02

这是我的解决方案:

您真正需要做的是使用 graphPathRequest。在android SDK中,已经提供了2个版本,其中之一是快速执行方法。另一种方法是在对此类请求对象调用执行之前发出请求并修改该请求。我的方法使用更高版本。

如果您在 FacebookActivity 内,只需致电:

Request r = new Request.newGraphPathRequest(getSession(), "fql", 
    new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
           // your FQL result will be stored in response.getGraphObject()
           Log.d("result", response.toString());
        }
    }
);
r.getParameters().putString("q", YOUR_QUERY_HERE);
r.executeAsync();

希望这会有所帮助。

请注意,我使用的是 AndroidSDK 3.0

Here is my solution:

What you really need to do is using a graphPathRequest. Within android SDK, it is already provided 2 versions of it one is quick execute method. Another is to make a request and modify that request before you call execute on such request object. My method use later version.

In case you are within FacebookActivity, simply call:

Request r = new Request.newGraphPathRequest(getSession(), "fql", 
    new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
           // your FQL result will be stored in response.getGraphObject()
           Log.d("result", response.toString());
        }
    }
);
r.getParameters().putString("q", YOUR_QUERY_HERE);
r.executeAsync();

Hope this helps.

Note that I'm using AndroidSDK 3.0

瞳孔里扚悲伤 2024-09-26 23:34:02

看起来 Android Facebook SDK 没有对旧 REST api 的参数进行 URL 编码。因此,当您发送大型 FQL 查询时,它无法处理所有空格和特殊字符。我可能会在 github 上发布一个分支来解决这个问题,但与此同时,您可以将 com.facebook.android.Util 中的第 26 行更改为:

sb.append(key + "=" + URLEncoder.encode(parameters.getString(key)));

注意那里的 URLEncoder 调用。这实际上是该方法的已弃用版本,但目前可以正常工作,当我推送到 github 时,我将包含正确的版本。

It looks like the Android Facebook SDK doesn't URL encode the params for the old REST api. So when you send a big FQL query it can't handle all the spaces and special characters. I'll probably put a fork up on github that fixes this, but in the meantime you can change line 26 in com.facebook.android.Util to:

sb.append(key + "=" + URLEncoder.encode(parameters.getString(key)));

Notice the URLEncoder call there. That's actually the deprecated version of the method but it will work fine for now, I'll include the correct one when I push to github.

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