如何在 tweepy 中的某个位置获取特定主题标签的推文? [英] How to get tweets of a particular hashtag in a location in a tweepy?

查看:28
本文介绍了如何在 tweepy 中的某个位置获取特定主题标签的推文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从特定位置(例如钦奈)获取特定主题标签的推文,用于分析数据.我真的是 Twitter API 和 tweepy 的新手.我发现搜索网址如下所示:https://api.twitter.com/1.1/search/tweets.json?q=%23cricket&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent

I wish to obtain tweets of a particular hashtag from a a particular location say Chennai for analysing data. I'm really new to Twitter API and tweepy. I found that the search url would look like this : https://api.twitter.com/1.1/search/tweets.json?q=%23cricket&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent

如何在 tweepy 中做同样的事情?到目前为止的代码:

How do the same in tweepy ? Code so far :

import tweepy

ckey = ""
csecret = ""
atoken = ""
asecret = ""

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
 'access_token_key':atoken, 'access_token_secret':asecret}
 auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)

cricTweet = tweepy.Cursor(api.search, q='cricket').items(10)

for tweet in cricTweet:
   print tweet.created_at, tweet.text, tweet.lang

推荐答案

您需要在 Tweepy 中使用 geocode 参数.使用搜索 URL 中的纬度/经度/半径,您的光标应如下定义:

You need to use the geocode parameter in Tweepy. Using the lat/long/radius from your search URL, your cursor should be defined like so:

tweepy.Cursor(api.search, q='cricket', geocode="-22.9122,-43.2302,1km").items(10)

请参阅 Tweepy API.search 文档有关您可以在搜索中包含的参数的更多信息.

See the Tweepy API.search documentation for more information on the parameters you can include in your search.

这篇关于如何在 tweepy 中的某个位置获取特定主题标签的推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆