How to get comments of Facebook Notes Items using

2019-07-04 03:43发布

问题:

I want to show Facebook Page's Notes items with those comments and likes using Graph API.

To do that, I'm using the asyncFacebookRunner in Facebook SDK.

Steps are like this:

  1. call asyncFacebookRunner.request to get Note Item with PageId

    mAsyncRunner.request(sAPIString, new NotesRequestListener(), null);

  2. 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
    
  3. call another asyncFacebookRunner.request to get comments of item(with NoteID)

    in getUserComments

    mAsyncRunner.request(sAPIString, new CommentRequestListener(), null);

Before getting comments(OnComplete in CommentRequestListener has not called), getWordsItems returns item array.

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.

回答1:

Use facebook object which has non-asynchronous request method. You need not implement listener method.

So, I suggest below means.

  1. use mAsyncRunner.request for first request call.
  2. use mFacebookRunner.request for second request call.

I hope it may help you:-)



回答2:

Using FQL - Facebook Query Language you can easily get all this information about any particular note info , Also to get likes on that and comments over it as like examples given in the links.