Graph APIを使って、コメントや好きなFacebookページのNotesアイテムを表示したい。アンドロイドアプリのいくつかのグラフAPIを使用してFacebookノート項目のコメントを取得するには?
これを行うには、Facebook SDKでasyncFacebookRunnerを使用しています。
手順は、このようなものです:
コールasyncFacebookRunner.requestはページID
mAsyncRunner.request(sAPIString、新しいNotesRequestListener()、ヌル)に注意項目を取得します。
応答があります。 (私は、関数呼び出しを強調表示することはできません。それを見つけるのは不便のため申し訳ありません。)
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をgetUserCommentsで(たNoteIDとの)項目のコメント
を取得するために
mAsyncRunner.request(sAPIString、新しいCommentRequestListener()、null);コメントを取得する前
(CommentRequestListenerでonCompleteのが呼び出されていない)、getWordsItemsは、アイテムの配列を返します。
コメントが表示されません。
コメントを取得するまでUIの更新を待つ方法を教えてください。 (非同期の呼び出しを同期するのはとても皮肉です)
ありがとうございます。
あなたを助けることを願っています。 – MKJParekh
これは私の望むものではありませんが、あなたの答えをありがとうございます。 私はFQLにコメントや好きなものを勧めてほしいと思います。 Androidのfacebook SDKを使用して、私はすでにNotesアイテムのコメントと好きなものを手に入れることができます。 最初にメモ項目のIDを取得します。そして、それのコメントや好きなものを入手してください。 コメント&好きがまだ届いていないうちに、アプリがアイテムの内容を表示するため、コメント&お気に入りが表示されません。 – FeedAtSpring
あなたはAsynccTask..whyを使用していますが、最初のタスクのonPostExecuteからコメントを得るために2番目のタスクを呼び出すことはできません... runOnUiThreadを使用してタスクのonPostExecuteでデータを取得すると、UIを更新できます – MKJParekh