python-twitter icon indicating copy to clipboard operation
python-twitter copied to clipboard

[GetSearch] Is there a way to get `search_metadata` in the result?

Open shubhams opened this issue 7 years ago • 2 comments

Although the comment above GetSearch() clearly mentions:

Returns:
          list: A sequence of twitter.Status instances, one for each message
          containing the term, within the bounds of the geocoded area, or
          given by the raw_query.

But is there any other way to get search_metadata using this API? I think return_json param was also removed from the method recently.

shubhams avatar Dec 27 '17 08:12 shubhams

I'm not sure what you mean by search_metadata, but the endpoint returns a json list from twitter as described here: https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html

That list is converted into a list of twitter.Status objects and returned, so there's no additional metadata to be retrieved from the endpoint.

jeremylow avatar Dec 28 '17 22:12 jeremylow

If you look at the Example Response section on the same documentation page, statuses is a JSON Array containing the tweets but below that, there is a search_metadata object that gives parameters like max_id and refresh_url. It looks like:

{
  "statuses": [...],
  "search_metadata": {
    "max_id": 250126199840518140,
    "since_id": 24012619984051000,
    "refresh_url": "?since_id=250126199840518145&q=%23freebandnames&result_type=mixed&include_entities=1",
    "next_results": "?max_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=mixed",
    "count": 4,
    "completed_in": 0.035,
    "since_id_str": "24012619984051000",
    "query": "%23freebandnames",
    "max_id_str": "250126199840518145"
  }
}

I was planning on using some of these for my application, like refreshing data from the last retrieved tweet. That's why I need access to the search_metadata object. Although, I agree that there must be workarounds for that, but there should be an option of getting it out-of-the-box, if the Twitter API provides it.

shubhams avatar Dec 29 '17 07:12 shubhams