Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to count number of Posts shared by Facebook Page.
"""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"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment