Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

facebook fql - How to send a FQL query with the new Android SDK

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...