public
Last active

How to count number of Posts shared by Facebook Page.

  • Download Gist
facebook_post_rate_example.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
"""This gist demonstrates how to automatically authenticate with Facebook's OAuth2
using fbconsole --- programmatically, without a browser --- and then count the number
of Posts, for example, on a Facebook Page.
"""
 
import fbconsole
import datetime
import time
 
# set up fbconsole
fbconsole.APP_ID = "xxxx_your_app_id"
fbconsole.AUTH_SCOPE = ["read_stream",]
page_id = "xxxx_your_Page_id"
 
# use fbconsole's automatically_authenticate method
# to login to the server programmatically
fbconsole.automatically_authenticate(
"xxxx_your_username",
"xxxx_your_password",
"xxxx_your_redirect_uri",
)
 
# get all the Posts for last year
now = datetime.datetime.now()
last_year = now - datetime.timedelta(days=days)
opts = {
"since": str(int(time.mktime(last_year.timetuple()))),
}
result = fbconsole.get("/%s/posts" % page_id, opts)
print len(result["data"])

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.