X Tutup
Skip to content

Commit 9bb81ea

Browse files
committed
Add GetSentDirectMessages()
1 parent a3bdd9e commit 9bb81ea

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

twitter.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ class Api(object):
21502150
>>> api.GetFollowers()
21512151
>>> api.GetFeatured()
21522152
>>> api.GetDirectMessages()
2153+
>>> api.GetSentDirectMessages()
21532154
>>> api.PostDirectMessage(user, text)
21542155
>>> api.DestroyDirectMessage(id)
21552156
>>> api.DestroyFriendship(user)
@@ -3231,6 +3232,42 @@ def GetDirectMessages(self, since=None, since_id=None, page=None):
32313232
data = self._ParseAndCheckTwitter(json)
32323233
return [DirectMessage.NewFromJsonDict(x) for x in data]
32333234

3235+
def GetSentDirectMessages(self, since=None, since_id=None, page=None):
3236+
'''Returns a list of the direct messages sent by the authenticating user.
3237+
3238+
The twitter.Api instance must be authenticated.
3239+
3240+
Args:
3241+
since:
3242+
Narrows the returned results to just those statuses created
3243+
after the specified HTTP-formatted date. [Optional]
3244+
since_id:
3245+
Returns results with an ID greater than (that is, more recent
3246+
than) the specified ID. There are limits to the number of
3247+
Tweets which can be accessed through the API. If the limit of
3248+
Tweets has occured since the since_id, the since_id will be
3249+
forced to the oldest ID available. [Optional]
3250+
page:
3251+
Specifies the page of results to retrieve.
3252+
Note: there are pagination limits. [Optional]
3253+
3254+
Returns:
3255+
A sequence of twitter.DirectMessage instances
3256+
'''
3257+
url = '%s/direct_messages/sent.json' % self.base_url
3258+
if not self._oauth_consumer:
3259+
raise TwitterError("The twitter.Api instance must be authenticated.")
3260+
parameters = {}
3261+
if since:
3262+
parameters['since'] = since
3263+
if since_id:
3264+
parameters['since_id'] = since_id
3265+
if page:
3266+
parameters['page'] = page
3267+
json = self._FetchUrl(url, parameters=parameters)
3268+
data = self._ParseAndCheckTwitter(json)
3269+
return [DirectMessage.NewFromJsonDict(x) for x in data]
3270+
32343271
def PostDirectMessage(self, user, text):
32353272
'''Post a twitter direct message from the authenticated user
32363273

0 commit comments

Comments
 (0)
X Tutup