Created
April 19, 2012 14:07
-
-
Save deanmalmgren/2421193 to your computer and use it in GitHub Desktop.
How to count number of Posts shared by Facebook Page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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