How to get all comments of a facebook post using facebook SDK in Python?
<p>I want to get all comments of a facebook post. We can extract comments by  passing the <code>limit()</code> in Api call But how we know the limit? I need all comments. </p>

<pre><code>https://graph.facebook.com/10153608167431961?fields=comments.limit(100).summary(true)&amp;access_token=LMN  
</code></pre>

<p>By using this </p>

<pre><code>data = graph.get_connections(id='10153608167431961', connection_name='comments')
</code></pre>

<p>I am getting few comments. 
How can I get all comments of a post?</p>

<p><strong>Edit</strong></p>

<pre><code>import codecs
import json
import urllib

import requests
B = "https://graph.facebook.com/"
P ="10153608167431961"
f = "?fields=comments.limit(4).summary(true)&amp;access_token="
T = "EAACb6lXwZDZD"
url = B+P+f+T


def fun(data):

    nextLink =  (data['comments']['paging']['next'])
    print(nextLink)
    for i in data['comments']['data']:
        print (i['message'])

    html = urllib.request.urlopen(nextLink).read()
    data = json.loads(html.decode('utf-8'))
    fun(data)

html = urllib.request.urlopen(url).read()
d = json.loads(html.decode('utf-8'))

fun(d)
</code></pre>

<p>It is giving the error</p>

<blockquote>
  <p>KeyError: 'comments'</p>
</blockquote>

<p>You need to implement paging to get all/more comments: <a href="https://developers.facebook.com/docs/graph-api/using-graph-api/#paging" rel="nofollow">https://developers.facebook.com/docs/graph-api/using-graph-api/#paging</a></p>

<p>Usually, this is done with a "recursive function", but you have to keep in mind that you may hit API limits if there are a LOT of comments. ItÂ´s better to load more comments on demand only.</p>

<p>Example for JavaScript: <a href="http://stackoverflow.com/questions/5023757/how-does-paging-in-facebook-javascript-api-works">How does paging in facebook javascript API works?</a></p>

python facebook facebook-graph-api recursion