[英]How to get comments of Facebook Notes Items using several Graph API in android app?
I want to show Facebook Page's Notes items with those comments and likes using Graph API. 我想使用Graph API显示带有这些注释和喜欢的Facebook页面的Notes项目。
To do that, I'm using the asyncFacebookRunner in Facebook SDK. 为此,我在Facebook SDK中使用asyncFacebookRunner。
Steps are like this: 步骤是这样的:
call asyncFacebookRunner.request to get Note Item with PageId 调用asyncFacebookRunner.request以获取带有PageId的Note Item
mAsyncRunner.request(sAPIString, new NotesRequestListener(), null); mAsyncRunner.request(sAPIString,new NotesRequestListener(),null);
Response has come. 响应已经到来。 ( I can't highlight function call. Sorry for inconvenient to find it.)
(我无法突出显示功能调用。很抱歉找不到它。)
public class NotesRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener { /** * Called when the request to get notes items has been completed. * Retrieve and parse and display the JSON stream. */ @Override public void onComplete(String response, Object state) { // TODO Auto-generated method stub Log.i("My_TAG", "onComplete with response, state"); try { // process the response here: executed in background thread final JSONObject json = new JSONObject(response); JSONArray arrNotesItems = json.getJSONArray("data"); int l = (arrNotesItems != null ? arrNotesItems.length() : 0); // !!!! // This has another request call // !!!! final ArrayList<WordsItem> newItems = WordsItem.getWordsItems(arrNotesItems,getActivity()); WordsActivity.this.runOnUiThread(new Runnable() { public void run() { wordsItems.clear(); wordsItems.addAll(newItems); aa.notifyDataSetChanged(); } }); // runOnUiThread } // try catch (JSONException e) { Log.i("My_TAG", "JSON Error in response"); } // catch } // onComplete ... other override methods ... } // Request Listener < Another Class > public static ArrayList<WordsItem> getWordsItems(JSONArray arrJSON, Activity activity) { ArrayList<WordsItem> wordsItems = new ArrayList<WordsItem>(); int l = (arrJSON != null ? arrJSON.length() : 0); try { WordsItem newItem; for (int i=0; i<l; i++) { JSONObject jsonObj = arrJSON.getJSONObject(i); String sTitle = jsonObj.getString("subject"); String sNoteID = jsonObj.getString("id"); ... get another fields here ... newItem = new WordItem(...); // !!!! // This has request call for comments // !!!! ArrayList<CommentItem> arrComment = getUserComments(sNoteID); wordsItems.add(newItem); } } catch (Exception e) { e.printStackTrace(); } return wordsItems; } // getWordsItems
call another asyncFacebookRunner.request to get comments of item(with NoteID) 调用另一个asyncFacebookRunner.request来获取item的注释(带NoteID)
in getUserComments 在getUserComments中
mAsyncRunner.request(sAPIString, new CommentRequestListener(), null); mAsyncRunner.request(sAPIString,new CommentRequestListener(),null);
Before getting comments(OnComplete in CommentRequestListener has not called), getWordsItems returns item array. 在获得注释之前(CommentRequestListener中的OnComplete未调用),getWordsItems返回item数组。
So I can't see the comments. 所以我看不到评论。
How can I wait to update UI till getting comments? 我怎么能等到更新用户界面才能收到评论? (It's so ironic to synchronize asynchronized calls.)
(同步异步调用真是太讽刺了。)
Thanks in advance. 提前致谢。
Use facebook object which has non-asynchronous request method. 使用具有非异步请求方法的facebook对象。 You need not implement listener method.
您无需实现侦听器方法。
So, I suggest below means. 所以,我建议以下方法。
I hope it may help you:-) 我希望它可以帮助你:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.