Created
October 23, 2012 21:48
-
-
Save AmeliaMN/3941867 to your computer and use it in GitHub Desktop.
Twitter and Facebook API introduction
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
# Twitter API | |
# In order to do the authenticated version, you need to download a ton of modules. | |
# Once you have a specific module on your desktop, move in to your home folder. | |
# Then, in the terminal window, cd to the folder. Once you're inside the folder, type | |
# python setup.py build | |
# python setup.py install | |
# python setup.py test | |
# and it will install the module. | |
# The ones you will need are simplejson, httplib2, python-oauth2, and python-twitter. | |
# Then, you have to register an application on twitter. I registered one for Mark's class, which anyone can play with. It has | |
# consumer_key = 'G5ZlcKqNUzYiGqHhK0pi2A' | |
# consumer_secret ='7qI8ZXzMnogWw0gU3IWhBtnksqjHXiwa1HVZnAScaLc' | |
# Once you have these things, you can add them to the get_access_token.py file in the folder that contains all the python-twitter things. | |
# Once you have both those codes in the file (on the Mac, at least, you need quotes around it) you can type | |
python get_access_token.py | |
# in the terminal command line. This should provide you with a URL to go to. I went there in my browser. | |
# This will link your twitter username with this application. | |
# Say yes and it will give you a pincode, which you can copy-paste into the command line prompt. | |
# The return of this will be the access token stuff. | |
# Your Twitter Access Token key: access_token_key='19520842-9Fk6Koo6EgLAZWFmrPWF2zUmfz3m7baBAr0YlLiDI' | |
# access_token_secret='UqeYPuOmt31X3qvE75EY4VQv8tJqJ5aLFagsqjNOJI' | |
# and then you can use these things when you get into python. | |
# Now lets open python! | |
import twitter | |
api=twitter.Api(consumer_key='G5ZlcKqNUzYiGqHhK0pi2A', consumer_secret='7qI8ZXzMnogWw0gU3IWhBtnksqjHXiwa1HVZnAScaLc', access_token_key='19520842-9Fk6Koo6EgLAZWFmrPWF2zUmfz3m7baBAr0YlLiDI', access_token_secret='UqeYPuOmt31X3qvE75EY4VQv8tJqJ5aLFagsqjNOJI') | |
users = api.GetFriends('AmeliaMN') | |
print [u.name for u in users] | |
statuses=api.GetUserTimeline('cocteau') | |
print [s.text for s in statuses] | |
# Facebook API: | |
# You can interact with this API easily through your browser. | |
# https://graph.facebook.com/amelia.mcnamara | |
# http://developers.facebook.com/docs/reference/api/ | |
# If you want to get more hardcore, you need more hardcore tools. | |
# First, you need the module pyfacebook, which you install in the same way. | |
# Then, you need a server and django. | |
# Lets play with the basic stuff in python: | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup | |
from BeautifulSoup import BeautifulStoneSoup | |
import BeautifulSoup | |
url="https://graph.facebook.com/amelia.mcnamara" | |
req=urllib2.Request(url) | |
response=urllib2.urlopen(req).read() | |
bs=BeautifulStoneSoup(response) | |
print bs.prettify() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment