Connecting to Twitter _ Google+ using Python Presentation
Transcript of Connecting to Twitter _ Google+ using Python Presentation
1
Connecting To Twitter & Google+ Using Python
+Wesley Chun@wescpy
corepython.comOSCON, Jul 2012
I Teach (SF, Aug 1-3)
2
I Write (mainly Core Python books)
I Code (now @ Google)
3
About You and This Talk
Assumes some Python knowledge/experienceWill not cover language basics here
Today focused on social mediaRelated code examplesCore Python Applications ProgrammingTwitter: chapters 11 and 13Google+: chapter 15
De facto microblogging platformIndividual 140-char limited messagesDelegated Authentication
4
Google+ Platform
Social for all Google productsSocial for your apps too
Plugins (+1s, Badges, etc.)Hangouts APIMobile PlatformHistory APIREST API
Developer sites
Twitterhttp://dev.twitter.com
Google+http://developers.google.com/+
5
Authentication vs. Authorization
AuthenticationUser identities (login+passwd)OpenID
Authorization(3rd-Party) Data accessOAuth
*Twitter Authentication
Identity Provider/server"Sign in with Twitter"
Delegated authenticationSites do auth opt-out, delegate to TwitterClosed system
6
*Google+ Authentication
Identity Provider/serverGoogle Accounts
Federated authenticationDecentralized, closer to "Internet SSO"Federation of identity providers
Google, Yahoo!, AOL, WordPress, etc.
http://developers.google.com/appengine/articles/openid
Getting started on Twitter
Create an apphttp://dev.twitter.com/apps
Keep an eye out for 4 values belowNeed them laterCONSUMER_KEYCONSUMER_SECRETACCESS_TOKENACCESS_TOKEN_SECRET
7
Twitter Tools You Need
http://dev.twitter.com/docs/twitter-libraries#pythonTweepy (2.x)
http://tweepy.github.compip/easy_install tweepy
Twython (2.x & 3.x)http://github.com/ryanmcgrath/twythonpip/easy_install twython
Or via source (python setup.py install)
Unauthorized (search)
twe_u.pytwy_u.py
8
*Authorization
OAuth2Data access
Without login+passwdSimilar to "valet key"
Pseudo-authenticationAssumes keyholder owner
*OAuth2 generic flow
App obtains client/consumer key & secretApp asks server for request token & authorization URLClient visits authorization URL & authorizes accessAuthorization returns back to app via callbackApp asks server for access tokenApp accesses data using access tokenAccess tokens typically timeoutApp can use refresh token to get new access tokenComment: generally non-trivial unless ...Note: all requests are signed (SHA1 hash typical)
9
*Simplified OAuth2 with Twitter
When accessing your own accountProfile, stream, etc.
"Permanent" access tokens providedNo need to use request or refresh tokens
http://dev.twitter.com/docs/auth/oauthhttp://dev.twitter.com/apps (select your app)
Authorized (user info)
twe_a.pytwy_a.py
10
Getting started on Google+
Create an apphttp://code.google.com/apis/console
Enable Google+ API AccessVia "Services" tab
Keep an eye out for the 3 values belowVia "API Access" tabAPI_KEYCLIENT_IDCLIENT_SECRET
Google+ Tools You Need
Google APIs Client Library for Python (2.x)http://code.google.com/p/google-api-python-clientpip/easy_install google-api-python-client
11
Unauthorized (search)
plus_u.py
*Simplified OAuth2 with Google
Google APIs Client for PythonBuilds uniform API "access point" (service)Includes oauth2client libraryAllows access to multiple Google APIs
http://code.google.com/p/google-api-python-client/wiki/OAuth2http://developers.google.com/accounts/docs/OAuth2
12
Authorized (user info)
plus_a.py
Next steps
Integrate snippets into your appFull OAuth2 flow (Twitter & Google)Also see Google+ Python Starter code
http://code.google.com/p/google-plus-python-starter
Access other Google APIs
13
Also see Chps 11, 13, 15
Conclusion
Python does social!Vendor-provided or 3rd-party libraries
Help simplify data authorizationDownload code at corepython.comLet's you integrate into CLI, web, mobile apps easily
14
Thank you!
Q&A+Wesley Chun ( plus.ly/wescpy )
@wescpycorepython.com
New or classic book... swing by booth!http://amzn.com/0132678209http://amzn.com/0132269937
Python course in SF: Aug 1-3
FINIS