如何让Android应用程序使用多个图形API的Facebook Notes项目的意见? [英] How to get comments of Facebook Notes Items using several Graph API in android app?
问题描述
我想告诉那些评论的Facebook页面的Notes项目和使用喜欢图形API。
I want to show Facebook Page's Notes items with those comments and likes using Graph API.
要做到这一点,我使用了Facebook SDK中的asyncFacebookRunner。
To do that, I'm using the asyncFacebookRunner in Facebook SDK.
步骤是这样的:
-
调用asyncFacebookRunner.request得到注意项目用的PageId
call asyncFacebookRunner.request to get Note Item with PageId
mAsyncRunner.request(sAPIString,新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
调用另一个asyncFacebookRunner.request获得项目注释(以NoteID)
call another asyncFacebookRunner.request to get comments of item(with NoteID)
在getUserComments
in getUserComments
mAsyncRunner.request(sAPIString,新CommentRequestListener(),NULL);
让意见(中的onComplete已CommentRequestListener不叫)之前,getWordsItems返回项数组。
Before getting comments(OnComplete in CommentRequestListener has not called), getWordsItems returns item array.
所以,我无法看到评论。
So I can't see the comments.
我如何可以等待更新UI,直到变得评论?
(它是如此讽刺异步调用同步。)
How can I wait to update UI till getting comments? (It's so ironic to synchronize asynchronized calls.)
先谢谢了。
推荐答案
有非异步请求方法使用Facebook对象。
你不需要实现监听器方法。
Use facebook object which has non-asynchronous request method. You need not implement listener method.
所以,我建议如下手段。
So, I suggest below means.
- 使用mAsyncRunner.request的第一个请求调用。
- 使用mFacebookRunner.request的第二个请求调用。
我希望这可以帮助你: - )
I hope it may help you:-)
这篇关于如何让Android应用程序使用多个图形API的Facebook Notes项目的意见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!