Top Banner
1 Connecting To Twitter & Google+ Using Python +Wesley Chun @wescpy corepython.com OSCON, Jul 2012 I Teach (SF, Aug 1-3)
14

Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

Aug 29, 2019

Download

Documents

phamnguyet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

1

Connecting To Twitter & Google+ Using Python

+Wesley Chun@wescpy

corepython.comOSCON, Jul 2012

I Teach (SF, Aug 1-3)

Page 2: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

2

I Write (mainly Core Python books)

I Code (now @ Google)

Page 3: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Twitter

De facto microblogging platformIndividual 140-char limited messagesDelegated Authentication

Page 4: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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/+

Page 5: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 6: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 7: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 8: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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)

Page 9: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 10: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 11: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 12: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 13: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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

Page 14: Connecting To Twitter & Google+ Using Pythonassets.en.oreilly.com/1/event/80/Connecting to Twitter _ Google+ using Python... · 3 About You and This Talk Assumes some Python knowledge/experience

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