如何发送新的Andr​​oid SDK一个FQL查询oid、Andr、FQL、SDK

2023-09-12 09:27:16 作者:目空一切的王

我一直在寻找在 developers.facebook 网站寻找一种方式来使用新的SDK和发送FQL查询,但好像一切都变和文档都在谈论各种其他的方式来要求朋友但不如具体的信息,使用我的应用程序或那些朋友呢?

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

 选择UID,名称,pic_square,从用户is_app_user其中uid中(从朋友选择UID2那里UID1 =我())
 

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

由于这似乎有利于返回的好友列表中的唯一请求是 Request.executeMyFriendsRequestAsync Request.newMyFriendsRequest 我以为they'ed是我的朋友,但都不允许FQL查询的微调。

我怎么能发送一个查询并取回好友列表或者至少 JSONArray

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

更新:的

我添加了code考虑这些问题就会让我创建这个查询:

 公共无效的onCreate(包savedInstanceState){
    //一些code
    this.openSession();
}

保护无效onSessionStateChange(SessionState会状态,异常除外){
    如果(state.isOpened()){
        会议activeSession =的getSession()getActiveSession()函数。
        facebook.setAccessToken(activeSession.getAccessToken());
        facebook.setAccessExpires(activeSession.getExpirationDate()的getTime());

        请求REQ = Request.newMyFriendsRequest(activeSession,新GraphUserListCallback(){

            @覆盖
            公共无效onCompleted(名单< GraphUser>的用户,响应响应){
                的System.out.println(response.toString());

            }
        });
        捆绑PARAMS =新包();
        params.putString(法,fql.query);
        params.putString(查询,选择UID,名称,pic_square,is_app_user+,从用户那里UID在
                +(选择朋友UID2那里UID1 =我()));
        req.setParameters(PARAMS);
        Request.executeBatchAsync(REQ);

    }
}
 

我这样做,以为它会修改该请求,并添加我想要的信息,但我得到这个错误:

  9月十号日至31日:36:31.647:E / AndroidRuntime(15986):显示java.lang.NullPointerException
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在com.sample.facebook.to.db.MainActivity $ 1.onCompleted(MainActivity.java:62)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在com.facebook.Request $ 2.onCompleted(Request.java:269)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在com.facebook.Request $ 4.run(Request.java:1197)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在android.os.Handler.handleCallback(Handler.java:587)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在android.os.Handler.dispatchMessage(Handler.java:92)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在android.os.Looper.loop(Looper.java:130)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在android.app.ActivityThread.main(ActivityThread.java:3691)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在java.lang.reflect.Method.invokeNative(本机方法)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在java.lang.reflect.Method.invoke(Method.java:507)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:907)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
9月10日至31日:36:31.647:E / AndroidRuntime(15986):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

您会做这样的事情:

 字符串fqlQuery =选择UID,名称,pic_square,从用户is_app_user其中uid中(从朋友选择UID2那里UID1 =我());
捆绑PARAMS =新包();
params.putString(Q,fqlQuery);

会话会话= Session.getActiveSession();
请求请求=新的请求(会话,
    / FQL
    参数,可以
    HttpMethod.GET,
    新Request.Callback(){
        公共无效onCompleted(响应响应){
        Log.i(TAG,得到的结果:+ response.toString());
    }
});
Request.executeBatchAsync(要求);
 

你基本上做一个图形API请求/ FQL端点查询到q参数来传递。

I've been searching over the developers.facebook website looking for a way to use the new SDK and send FQL queries but it seems like everything has changed and the documentation is talking about all sorts of other ways to request me or friends but not specific information such as are those friends using my app or not?

so I wrote down a nice FQL query

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

and now, all I have to do is run it.

Since the only requests that seem good for returning a list of friends are Request.executeMyFriendsRequestAsync and Request.newMyFriendsRequest I assumed they'ed be my friends, but both don't allow the fine tuning of a FQL query.

how can I send a query and get back a list of friends or at least a JSONArray?

the Hackbook - FQL Query tutorial is using the old version of the SDK and I don't know what to do.

UPDATE:

I added these lines of code thinking it will let me create this query:

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);

    }
}

I did this, thinking it will edit the request and add the information I want but I got this error:

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)

解决方案

You would do something like this:

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);

You're basically making a Graph API request to the "/fql" endpoint with your query passed in to the "q" parameter.