xitiomet is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againpython-twitter / README
- commit
- 82aae45f64f2
- parent
- a58f4a7ad991
- branch
- default
Added GetMentions to twitter.py
1 |
babe112cc95f
|
=Python Twitter= |
2 |
4805aee792f0
|
|
3 |
babe112cc95f
|
_A python wrapper around the Twitter API_ |
4 |
babe112cc95f
|
|
5 |
babe112cc95f
|
Author: `DeWitt Clinton <dewitt@google.com>` |
6 |
babe112cc95f
|
|
7 |
babe112cc95f
|
==Introduction== |
8 |
babe112cc95f
|
|
9 |
babe112cc95f
|
This library provides a pure python interface for the Twitter API. |
10 |
babe112cc95f
|
|
11 |
babe112cc95f
|
Twitter (http://twitter.com) provides a service that allows people to |
12 |
babe112cc95f
|
connect via the web, IM, and SMS. Twitter exposes a web services API |
13 |
babe112cc95f
|
(http://twitter.com/help/api) and this library is intended to make |
14 |
babe112cc95f
|
it even easier for python programmers to use. |
15 |
babe112cc95f
|
|
16 |
4805aee792f0
|
|
17 |
babe112cc95f
|
==Building== |
18 |
4805aee792f0
|
|
19 |
babe112cc95f
|
*From source:* |
20 |
4805aee792f0
|
|
21 |
8a1b3c54b6cd
|
Install the dependencies: |
22 |
8a1b3c54b6cd
|
|
23 |
8a1b3c54b6cd
|
http://cheeseshop.python.org/pypi/simplejson |
24 |
8a1b3c54b6cd
|
|
25 |
babe112cc95f
|
Download the latest python-twitter library from: |
26 |
babe112cc95f
|
|
27 |
babe112cc95f
|
http://code.google.com/p/python-twitter/ |
28 |
babe112cc95f
|
|
29 |
ebb87f97ce33
|
|
30 |
babe112cc95f
|
Untar the source distribution and run: |
31 |
babe112cc95f
|
|
32 |
babe112cc95f
|
{{{ |
33 |
dbe3b23bfd08
|
$ python setup.py build |
34 |
8a1b3c54b6cd
|
$ python setup.py install |
35 |
8a1b3c54b6cd
|
}}} |
36 |
8a1b3c54b6cd
|
|
37 |
8a1b3c54b6cd
|
*Testing* |
38 |
8a1b3c54b6cd
|
|
39 |
8a1b3c54b6cd
|
With setuptools installed: |
40 |
8a1b3c54b6cd
|
|
41 |
8a1b3c54b6cd
|
{{{ |
42 |
8a1b3c54b6cd
|
$ python setup.py test |
43 |
8a1b3c54b6cd
|
}}} |
44 |
8a1b3c54b6cd
|
|
45 |
8a1b3c54b6cd
|
Without setuptools installed: |
46 |
8a1b3c54b6cd
|
|
47 |
8a1b3c54b6cd
|
{{{ |
48 |
a74805362b3b
|
$ python twitter_test.py |
49 |
babe112cc95f
|
}}} |
50 |
babe112cc95f
|
|
51 |
8998cc6946dd
|
==Getting the code== |
52 |
8998cc6946dd
|
|
53 |
8998cc6946dd
|
View the trunk at: |
54 |
8998cc6946dd
|
|
55 |
8998cc6946dd
|
http://python-twitter.googlecode.com/svn/trunk/ |
56 |
8998cc6946dd
|
|
57 |
8998cc6946dd
|
Check out the latest development version anonymously with: |
58 |
8998cc6946dd
|
|
59 |
8998cc6946dd
|
{{{ |
60 |
8998cc6946dd
|
$ svn checkout http://python-twitter.googlecode.com/svn/trunk/ python-twitter |
61 |
8998cc6946dd
|
}}} |
62 |
8998cc6946dd
|
|
63 |
8998cc6946dd
|
==Documentation== |
64 |
8998cc6946dd
|
|
65 |
8998cc6946dd
|
View the last release API documentation at: |
66 |
8998cc6946dd
|
|
67 |
a3421fedecb0
|
http://static.unto.net/python-twitter/0.6/doc/twitter.html |
68 |
8998cc6946dd
|
|
69 |
babe112cc95f
|
==Using== |
70 |
babe112cc95f
|
|
71 |
babe112cc95f
|
The library provides a python wrapper around the Twitter API and |
72 |
babe112cc95f
|
the twitter data model. |
73 |
babe112cc95f
|
|
74 |
babe112cc95f
|
*Model:* |
75 |
babe112cc95f
|
|
76 |
b66b34fe3b78
|
The three model classes are twitter.Status, twitter.User, and |
77 |
b66b34fe3b78
|
twitter.DirectMessage. The API methods return instances of these |
78 |
b66b34fe3b78
|
classes. |
79 |
babe112cc95f
|
|
80 |
b66b34fe3b78
|
To read the full API for twitter.Status, twitter.User, or |
81 |
b66b34fe3b78
|
twitter.DirectMessage, run: |
82 |
babe112cc95f
|
|
83 |
babe112cc95f
|
{{{ |
84 |
babe112cc95f
|
$ pydoc twitter.Status |
85 |
babe112cc95f
|
$ pydoc twitter.User |
86 |
b66b34fe3b78
|
$ pydoc twitter.DirectMessage |
87 |
babe112cc95f
|
}}} |
88 |
babe112cc95f
|
|
89 |
babe112cc95f
|
*API:* |
90 |
babe112cc95f
|
|
91 |
babe112cc95f
|
The API is exposed via the twitter.Api class. |
92 |
babe112cc95f
|
|
93 |
babe112cc95f
|
To create an instance of the twitter.Api class: |
94 |
babe112cc95f
|
|
95 |
babe112cc95f
|
{{{ |
96 |
babe112cc95f
|
>>> import twitter |
97 |
babe112cc95f
|
>>> api = twitter.Api() |
98 |
babe112cc95f
|
}}} |
99 |
babe112cc95f
|
|
100 |
90377483d9fa
|
To create an instance of the twitter.Api with login credentials (many API |
101 |
90377483d9fa
|
calls required the client to be authenticated): |
102 |
90377483d9fa
|
|
103 |
90377483d9fa
|
>>> api = twitter.Api(username='username', password='password) |
104 |
90377483d9fa
|
|
105 |
babe112cc95f
|
To fetch the most recently posted public twitter status messages: |
106 |
babe112cc95f
|
|
107 |
babe112cc95f
|
{{{ |
108 |
babe112cc95f
|
>>> statuses = api.GetPublicTimeline() |
109 |
babe112cc95f
|
>>> print [s.user.name for s in statuses] |
110 |
98ab67ff72af
|
[u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone'] |
111 |
babe112cc95f
|
}}} |
112 |
babe112cc95f
|
|
113 |
97fa5229a449
|
To fetch a single user's public status messages, where "user" is either |
114 |
97fa5229a449
|
a Twitter "short name" or their user id. |
115 |
babe112cc95f
|
|
116 |
babe112cc95f
|
{{{ |
117 |
97fa5229a449
|
>>> statuses = api.GetUserTimeline(user) |
118 |
babe112cc95f
|
>>> print [s.text for s in statuses] |
119 |
babe112cc95f
|
}}} |
120 |
babe112cc95f
|
|
121 |
90377483d9fa
|
To fetch a list a user's friends (requires authentication): |
122 |
babe112cc95f
|
|
123 |
babe112cc95f
|
{{{ |
124 |
90377483d9fa
|
>>> users = api.GetFriends() |
125 |
babe112cc95f
|
>>> print [u.name for u in users] |
126 |
babe112cc95f
|
}}} |
127 |
babe112cc95f
|
|
128 |
90377483d9fa
|
To post a twitter status message (requires authentication): |
129 |
babe112cc95f
|
|
130 |
babe112cc95f
|
{{{ |
131 |
babe112cc95f
|
>>> status = api.PostUpdate(username, password, 'I love python-twitter!') |
132 |
babe112cc95f
|
>>> print status.text |
133 |
babe112cc95f
|
I love python-twitter! |
134 |
babe112cc95f
|
}}} |
135 |
babe112cc95f
|
|
136 |
4da5ec4d173a
|
There are many more API methods, to read the full API documentation: |
137 |
babe112cc95f
|
|
138 |
babe112cc95f
|
{{{ |
139 |
babe112cc95f
|
$ pydoc twitter.Api |
140 |
babe112cc95f
|
}}} |
141 |
babe112cc95f
|
|
142 |
babe112cc95f
|
==Todo== |
143 |
babe112cc95f
|
|
144 |
babe112cc95f
|
Patches and bug reports are welcome, just please keep the style |
145 |
babe112cc95f
|
consistent with the original source. |
146 |
babe112cc95f
|
|
147 |
babe112cc95f
|
Add more example scripts. |
148 |
babe112cc95f
|
|
149 |
babe112cc95f
|
The twitter.Status and twitter.User classes are going to be hard |
150 |
babe112cc95f
|
to keep in sync with the API if the API changes. More of the |
151 |
babe112cc95f
|
code could probably be written with introspection. |
152 |
babe112cc95f
|
|
153 |
babe112cc95f
|
Statement coverage of twitter_test is only about 80% of twitter.py. |
154 |
babe112cc95f
|
|
155 |
babe112cc95f
|
The twitter.Status and twitter.User classes could perform more validation |
156 |
babe112cc95f
|
on the property setters. |
157 |
babe112cc95f
|
|
158 |
90cd841771cf
|
==More Information== |
159 |
90cd841771cf
|
|
160 |
90cd841771cf
|
Please visit http://groups.google.com/group/python-twitter for more discussion. |
161 |
90cd841771cf
|
|
162 |
90cd841771cf
|
==Contributors== |
163 |
90cd841771cf
|
|
164 |
a10f9a46dc3d
|
Additional thanks to Pierre-Jean Coudert, Omar Kilani, Jodok Batlogg, |
165 |
11710035d0b9
|
edleaf,glen.tregoning, Brad Choate, Jim Cortez, Jason Lemoine, Thomas |
166 |
935cf080b638
|
Dyson, Robert Laquey, and the rest of the python-twitter mailing list. |
167 |
90cd841771cf
|
|
168 |
babe112cc95f
|
==License== |
169 |
babe112cc95f
|
|
170 |
babe112cc95f
|
{{{ |
171 |
4805aee792f0
|
Copyright 2007 Google Inc. All Rights Reserved. |
172 |
babe112cc95f
|
|
173 |
babe112cc95f
|
Licensed under the Apache License, Version 2.0 (the 'License'); |
174 |
4805aee792f0
|
you may not use this file except in compliance with the License. |
175 |
4805aee792f0
|
You may obtain a copy of the License at |
176 |
babe112cc95f
|
|
177 |
4805aee792f0
|
http://www.apache.org/licenses/LICENSE-2.0 |
178 |
babe112cc95f
|
|
179 |
4805aee792f0
|
Unless required by applicable law or agreed to in writing, software |
180 |
babe112cc95f
|
distributed under the License is distributed on an 'AS IS' BASIS, |
181 |
4805aee792f0
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
182 |
4805aee792f0
|
See the License for the specific language governing permissions and |
183 |
4805aee792f0
|
limitations under the License. |
184 |
babe112cc95f
|
}}} |