2011-12-05 6 views
3

Graph APIを使って、コメントや好きなFacebookページのNotesアイテムを表示したい。アンドロイドアプリのいくつかのグラフAPIを使用してFacebookノート項目のコメントを取得するには?

これを行うには、Facebook SDKでasyncFacebookRunnerを使用しています。

手順は、このようなものです:

  1. コールasyncFacebookRunner.requestはページID

    mAsyncRunner.request(sAPIString、新しいNotesRequestListener()、ヌル)に注意項目を取得します。

  2. 応答があります。 (私は、関数呼び出しを強調表示することはできません。それを見つけるのは不便のため申し訳ありません。)

    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 
    
  3. コール別asyncFacebookRunner.requestをgetUserCommentsで(たNoteIDとの)項目のコメント

    を取得するために

    mAsyncRunner.request(sAPIString、新しいCommentRequestListener()、null);コメントを取得する前

(CommentRequestListenerでonCompleteのが呼び出されていない)、getWordsItemsは、アイテムの配列を返します。

コメントが表示されません。

コメントを取得するまでUIの更新を待つ方法を教えてください。 (非同期の呼び出しを同期するのはとても皮肉です)

ありがとうございます。

答えて

0

使用FQL - Facebookのクエリ言語を使えば、簡単にもリンクに与えられた例などlikes on thatcomments over itを取得するには、任意のparticular note info に関するすべての情報を得ることができます。

+0

あなたを助けることを願っています。 – MKJParekh

+0

これは私の望むものではありませんが、あなたの答えをありがとうございます。 私はFQLにコメントや好きなものを勧めてほしいと思います。 Androidのfacebook SDKを使用して、私はすでにNotesアイテムのコメントと好きなものを手に入れることができます。 最初にメモ項目のIDを取得します。そして、それのコメントや好きなものを入手してください。 コメント&好きがまだ届いていないうちに、アプリがアイテムの内容を表示するため、コメント&お気に入りが表示されません。 – FeedAtSpring

+0

あなたはAsynccTask..whyを使用していますが、最初のタスクのonPostExecuteからコメントを得るために2番目のタスクを呼び出すことはできません... runOnUiThreadを使用してタスクのonPostExecuteでデータを取得すると、UIを更新できます – MKJParekh

1

非同期リクエストメソッドを持つfacebookオブジェクトを使用します。 リスナーメソッドを実装する必要はありません。

したがって、以下のことをお勧めします。

  1. 最初のリクエストコールでmAsyncRunner.requestを使用します。
  2. 2番目のリクエストコールでmFacebookRunner.requestを使用します。

私はそれは私があなたの上に述べたようにFacbookをキシに考えるthese..butすべてが簡単にすべてのそれらのものを得ることができます取得するには、AndroidのFacebook SDKプロジェクトを使用していない:-)

関連する問題