Bulk Statuses Route /statuses/lookup.json
See original GitHub issueHello @bear,
While using this library today (thanks for the convenience!), I found that a particular route was missing, so I subclassed twitter.Api
and added a method for my use-case (I was able to use the dicts decoded from json). However, when integrating my changes with the existing object structure, it seems that there’s a mismatch between the statuses at this route, and the status object returned at /statuses/show.json
. I’ve included my basic patch, and I’ll try to integrate it more fully once I get back to work tomorrow. The issue comes up at line 546 of twitter/status.py
. As I said, I’ll dig into this more deeply tomorrow, clean up the code, and include tests.
AttributeError
546 media = [m for m in data['extended_entities']['media']]
547
--> 548 return Status(created_at=data.get('created_at', None),
549 favorited=data.get('favorited', None),
550 favorite_count=data.get('favorite_count', None),
The status objects returned by the statuses/lookup.json
route do not contain “extended_entities”.
Here is the patch (work in progress).
From 3fdfcc2ad35af327a65ec2a448a86a32e3ce5b65 Mon Sep 17 00:00:00 2001
From: Arthur Maciejewicz <arthur@signafire.com>
Date: Tue, 29 Sep 2015 19:57:54 -0400
Subject: [PATCH] Added bulk statuses
---
twitter/api.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/twitter/api.py b/twitter/api.py
index d38e1aa..5e4128e 100644
--- a/twitter/api.py
+++ b/twitter/api.py
@@ -639,6 +639,69 @@ class Api(object):
return [Status.NewFromJsonDict(x) for x in data]
+ def StatusesLookup(self,
+ ids,
+ trim_user=False,
+ include_entities=True,
+ map=True):
+ """Returns a list of status messages, specified by comma delimited ids
+
+ The twitter.Api instance must be authenticated.
+ You are limited to 100 ids at a time.
+
+ Args:
+ ids:
+ An iterable of numeric ID(s) of the status(es) you are trying to retrieve.
+ trim_user:
+ When set to True, each tweet returned in a timeline will include
+ a user object including only the status authors numerical ID.
+ Omit this parameter to receive the complete user object. [Optional]
+ include_entities:
+ If False, the entities node will be disincluded.
+ This node offers a variety of metadata about the tweet in a
+ discreet structure, including: user_mentions, urls, and
+ hashtags. [Optional]
+ map:
+ tweets that do not exist or cannot be viewed by the current
+ user will have their key represented but with an explicitly
+ null value paired with it. [Optional]
+
+
+ Returns:
+ A list of twitter.Status instances representing the status messages
+ """
+
+ url = '%s/statuses/lookup.json' % (self.base_url)
+
+ for id in ids:
+ try:
+ foo = long(id)
+ except ValueError:
+ raise TwitterError({'message': "'ids' must all be integers."})
+
+ parameters = {}
+
+ parameters['id'] = ",".join(str(i) for i in ids)
+
+ if trim_user:
+ parameters['trim_user'] = 1
+
+ if not include_entities:
+ parameters['include_entities'] = 'false'
+
+ if map:
+ parameters['map'] = 'true'
+
+
+ json_data = self._RequestUrl(url, 'GET', data=parameters)
+ data = self._ParseAndCheckTwitter(json_data.content)
+ print data
+
+ statuses = [Status.NewFromJsonDict(status) for status in data]
+
+ return statuses
+
+
def GetStatus(self,
id,
trim_user=False,
--
2.4.5
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
I had a need for this functionality, and implemented the following based on the patch from @Zintinio and the current python-twitter code. I did not observe any differences between the data returned with this and the data returned by GetStatus.
However, I did encounter a bug in python-twitter’s POST support: the setting of tweet_mode is not honoured. Adding
data['tweet_mode'] = self.tweet_mode
before the relevantrequests.post
call inApi._RequestUrl
fixed this for me. Perhaps someone more knowledgeable than me could advise if this needs to be done for all POST requests.If you would like this in a pull request, I can do so. I was lazy so I implemented this in my own code and assigned it to
twitter.Api.GetStatuses
.That’s a good call. We should add the
tweet_mode
param to all the_RequestUrl*
methods.