9

我一直在搜索developer.facebook网站,寻找使用新 SDK 和发送 FQL 查询的方法,但似乎一切都发生了变化,文档正在讨论各种其他请求方式,mefriends不是特定信息,例如那些朋友是否使用我的应用程序?

所以我写了一个很好的 FQL 查询

select uid, name, pic_square, is_app_user from user where uid in (select uid2 from friend where uid1 = me())

现在,我所要做的就是运行它。

因为返回朋友列表的唯一请求似乎是我认为他们是我的朋友Request.executeMyFriendsRequestAsyncRequest.newMyFriendsRequest但两者都不允许对 FQL 查询进行微调。

如何发送查询并取回朋友列表或至少一个JSONArray

Hackbook - FQL Query 教程使用的是旧版本的 SDK,我不知道该怎么办。

更新:

我添加了这些代码行,认为它可以让我创建这个查询:

public void onCreate(Bundle savedInstanceState) {
    // SOME CODE
    this.openSession();
}

protected void onSessionStateChange(SessionState state, Exception exception) {
    if (state.isOpened()) {
        Session activeSession = getSession().getActiveSession();
        facebook.setAccessToken(activeSession.getAccessToken());
        facebook.setAccessExpires(activeSession.getExpirationDate().getTime());

        Request req = Request.newMyFriendsRequest(activeSession, new GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                System.out.println(response.toString());

            }
        });
        Bundle params = new Bundle();
        params.putString("method", "fql.query");
        params.putString("query", "select uid, name, pic_square, is_app_user " + "from user where uid in "
                + "(select uid2 from friend where uid1 = me())");
        req.setParameters(params);
        Request.executeBatchAsync(req);

    }
}

我这样做了,认为它会编辑请求并添加我想要的信息,但我收到了这个错误:

10-31 09:36:31.647: E/AndroidRuntime(15986): java.lang.NullPointerException
10-31 09:36:31.647: E/AndroidRuntime(15986):    at com.sample.facebook.to.db.MainActivity$1.onCompleted(MainActivity.java:62)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at com.facebook.Request$2.onCompleted(Request.java:269)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at com.facebook.Request$4.run(Request.java:1197)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at android.os.Handler.handleCallback(Handler.java:587)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at android.os.Looper.loop(Looper.java:130)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at android.app.ActivityThread.main(ActivityThread.java:3691)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at java.lang.reflect.Method.invokeNative(Native Method)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at java.lang.reflect.Method.invoke(Method.java:507)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-31 09:36:31.647: E/AndroidRuntime(15986):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

21

你会做这样的事情:

String fqlQuery = "select uid, name, pic_square, is_app_user from user where uid in (select uid2 from friend where uid1 = me())";
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);

您基本上是在向“/fql”端点发出 Graph API 请求,并将查询传递给“q”参数。

于 2012-10-31T17:12:41.837 回答
2

试试这个方法

void a(){
         String fqlQuery = "{" +
                 "'friends':'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25'," +
                 "'friendinfo':'SELECT uid, name, pic_square FROM user WHERE uid IN " +
                 "(SELECT uid2 FROM #friends)'," +
                 "}";
           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, "Result: " + response.toString());
                   }                  
           }); 
           Request.executeBatchAsync(request);    
    }
于 2013-04-11T15:24:38.533 回答
1

这是讨论此问题的线程的链接:FQL using facebook android SDK

您也可以使用以下格式发出 Graph API 调用:graph.facebook.com/fql?q=QUERY

所以在你的情况下,它可能看起来像:graph.facebook.com/fql?q=select uid, name, pic_square, is_app_user from user where uid in (select uid2 from friend where uid1 = me())

编辑:似乎此功能的示例存在于示例应用程序“Hackbook”中 https://github.com/facebook/facebook-android-sdk/blob/master/examples/Hackbook/src/com/facebook/android/ FQLQuery.java

最值得注意的是,这段代码(第 61 行):

String query = mFQLQuery.getText().toString();
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
Utility.mAsyncRunner.request(null, params, new FQLRequestListener());
于 2012-10-30T19:03:43.677 回答