Skip to content

Instantly share code, notes, and snippets.

@deanmalmgren
Created April 19, 2012 14:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save deanmalmgren/2421193 to your computer and use it in GitHub Desktop.
Save deanmalmgren/2421193 to your computer and use it in GitHub Desktop.
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