1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
How to use the twyt Python module
-------------------------------------
o This document is written for developers who are interested in using the twyt
Python module for developing Twitter applications. If you only wish to use
the twyt commandline program, consult the README and the twyt man page for
further information.
o The Twitter API functions are encapsulated in the twitter.Twitter class. This
is really all you need to start using the basics of twyt but other modules
and classes are provided to allow you to make sense of the data returned from
Twitter. Here we briefly describe how to post a status message, delete it and
then list the public timeline:
from twyt import twitter, data
t = twitter.Twitter()
t.set_auth("username", "password")
return_val = t.status_update("Testing 123")
The above snippet instantiates a Twitter object and then tells it the user's
Twitter user name and password. It then calls the Twitter object's
status_update() method to send the new status message - in this example
"Testing 123" - to Twitter. That's how simple it is to update your Twitter
status with twyt! We continue...
s = data.Status()
s.load_json(return_val)
print s
t.status_destroy(s.id)
This snippet shows how to use a data.Status() object to make sense of the
data that Twitter returns when we post our new status message. Once the
returned data (return_val) is loaded into the Status object s, the Status
object represents the status message returned. `print s' prints a string
representation of the status message (see docs for the format). We then
decide our status message was boring and call status_destroy() on its ID to
tell Twitter to delete the status message. That's about all you need to get
started. See the pydocs in twitter.py (import twyt.twitter; help(twitter))
to see the rest of the Twitter API functions you can call.
o That's about as simple as it gets. The world is now your oyster. Have fun!
|