Friday, September 23, 2011

[Python] Easy Facebook Scripting.

Need a small and neat api for doing Facebook scripting? Look no further!


from urllib import urlretrieve
import imp
urlretrieve('https://raw.github.com/gist/1194123/fbconsole.py', '.fbconsole.py'
fb = imp.load_source('fb', '.fbconsole.py')
fb.AUTH_SCOPE = ['publish_stream']
fb.authenticate()
status = fb.graph_post("/me/feed", {"message":"Hello from my awesome script"})
#Note: Recommend that you download fbconsole.py locally with eg. wget https://raw.github.com/gist/1194123/fbconsole.py

Post a status update:
status = fb.graph_post("/me/feed", {"message":"Hello from my awesome script"})

Fetch likes on a status update:

likes = fb.graph("/"+status["id"]+"/likes")
Delete a status update:
fb.graph_delete("/"+status["id"])
Upload a photo:

fb.graph_post("/me/photos", {"message":"My photo", "source":open("my-photo.jpg")})
Query FQL tables:
friends = fb.fql("SELECT name FROM user WHERE uid IN "
"(SELECT uid2 FROM friend WHERE uid1 = me())")


Source:  Easy Facebook Scripting in Python

No comments:

Post a Comment