我一直在搜索
developers.facebook网站,寻找一种使用新SDK并发送FQL查询的方法,但似乎所有内容都发生了变化,文档正在谈论各种其他方式来请求我或朋友,但没有具体的信息那些使用我的应用程序的朋友也是如此?
所以我写了一个很好的FQL查询
select uid,name,pic_square,is_app_user from user where uid in (select uid2 from friend where uid1 = me())
现在,我所要做的就是运行它.
由于对返回朋友列表似乎很好的唯一请求是Request.executeMyFriendsRequestAsync和Request.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,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)
解决方法
你会做这样的事情:
String fqlQuery = "select uid,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);
您基本上将一个Graph API请求发送到“/ fql”端点,并将查询传递给“q”参数.