Difference between revisions of "Python: Twitter"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 17: | Line 17: | ||
==Test API Twitter== | ==Test API Twitter== | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
API: | API: | ||
Line 74: | Line 24: | ||
To create an instance of the twitter.Api class: | To create an instance of the twitter.Api class: | ||
− | + | import twitter | |
− | + | api = twitter.Api(consumer_key='consumer_key', | |
+ | consumer_secret='consumer_secret', | ||
+ | access_token_key='access_token', | ||
+ | access_token_secret='access_token_secret') | ||
+ | print api.VerifyCredentials() {"id": 16133, "location": "Philadelphia", "name": "bear"} | ||
− | + | Print Public TimeLine | |
− | + | statuses = api.GetPublicTimeline() | |
− | + | print [s.user.name for s in statuses] | |
− | + | [u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone'] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Print / fetch single "user" public message | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | statuses = api.GetUserTimeline(user) | |
+ | print [s.text for s in statuses] | ||
− | |||
− | |||
− | + | Print / fetch user friends | |
− | + | users = api.GetFriends() | |
− | + | print [u.name for u in users] | |
− | + | Post a Twitter status message | |
− | + | status = api.PostUpdate('I love python-twitter!') | |
− | + | print status.text | |
− | |||
− | + | I love python-twitter! | |
− | + | Ada banyak API method, baca | |
+ | $ pydoc twitter.Api | ||
+ | $ pydoc twitter.Status | ||
+ | $ pydoc twitter.User | ||
+ | $ pydoc twitter.DirectMessage | ||
==Referensi== | ==Referensi== | ||
* https://code.google.com/p/python-twitter/ | * https://code.google.com/p/python-twitter/ |
Revision as of 07:38, 3 December 2015
Sumber: https://code.google.com/p/python-twitter/
Instal Dependency dan Python Twitter
Lakukan
cd /usr/local/src wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py python ez_setup.py --insecure easy_install simplejson easy_install httplib2-master.zip easy_install python-oauth2-master.zip easy_install python-twitter-1.1.tar.gz
Test API Twitter
API:
The API is exposed via the twitter.Api class.
To create an instance of the twitter.Api class:
import twitter api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret') print api.VerifyCredentials() {"id": 16133, "location": "Philadelphia", "name": "bear"}
Print Public TimeLine
statuses = api.GetPublicTimeline() print [s.user.name for s in statuses] [u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone']
Print / fetch single "user" public message
statuses = api.GetUserTimeline(user) print [s.text for s in statuses]
Print / fetch user friends
users = api.GetFriends() print [u.name for u in users]
Post a Twitter status message
status = api.PostUpdate('I love python-twitter!') print status.text
I love python-twitter!
Ada banyak API method, baca
$ pydoc twitter.Api $ pydoc twitter.Status $ pydoc twitter.User $ pydoc twitter.DirectMessage