简体   繁体   English

获取Twitter API返回搜索结果而不是结果摘要

[英]Getting twitter api to return search results instead of results summary

I'm using requests to grab tweets from a geographically bounded area. 我正在使用一些请求来从某个地理范围内的区域获取推文。 When I try to print the results, I get what looks like the summary of the results rather than the results themselves. 当我尝试打印结果时,得到的结果看起来像是摘要,而不是结果本身。 My code is: 我的代码是:

from __future__ import unicode_literals
import requests
from requests_oauthlib import OAuth1
import pprint


consumer_key=""
consumer_secret=""
access_key=""
access_token_secret=""
access_token=""
header_auth=True

url = 'https://api.twitter.com/1.1/search/tweets.json'

headeroauth = OAuth1(consumer_key, consumer_secret,
                     access_key, access_token_secret,
                     signature_type='auth_header')  

query_params = { 'q': 'the',
                 'geocode': '33.520661, -86.80249, 50mi' 
               }

response = requests.get(url, auth=headeroauth, params=query_params)
data = response.json()
pprint.pprint(data)

And the response I get back is: 我得到的答复是:

{u'search_metadata': {u'count': 15, u'completed_in': 0.025000000000000001,
u'max_id_str': u'349363977614143489', u'since_id_str': u'0', u'refresh_url': u'
since_id=349363977614143489&q=the&geocode=33.520661%2C%20
86.80249%2C%2050mi&include_entities=1', u'since_id': 0, u'query': u'the', u'max_id': 349363977614143489}, u'statuses': []}

How do I set it up to return the actual content of the tweets? 如何设置它以返回推文的实际内容? Thanks! 谢谢!

In twitter API's documentation when you use "search", you got this dict object and in statuses key you should have a list of tweets according to your search options. twitter API的文档中,当您使用“搜索”时,会获得此dict对象,并且在statuses键中,应根据您的搜索选项提供一条推文列表。 Be sure that tweets in statuses are dict objects too, and its content are in text key 确保状态中的推文也是dict对象,并且其内容在text键中

Remove the spaces in your geocode parameter and it should return statuses: 删除地址解析参数中的空格,它应返回以下状态:

query_params = { 'q': 'the',
                 'geocode': '33.520661,-86.80249,50mi' 
               }

Also check out the Twitter dev console for testing out your queries. 另外,请查看Twitter开发者控制台以测试您的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM