简体   繁体   English

使用场所ID在Twitter-Python中获取推文

[英]Getting tweets in twitter-python using using place id

I am trying to get the tweets which contain a particular search term and have been tweeted from Mumbai . 我正在尝试获取包含特定搜索词的推文,这些推文是从孟买发布的。 I know the place id of Mumbai is: 7929cea6bd5b32bd . 我知道孟买的地方ID是:7929cea6bd5b32bd。 I am using python-twitter in python 2.7.9 and the following code: 我在python 2.7.9和以下代码中使用python-twitter:

    search_string="place:7929cea6bd5b32bd string"
    alltweets=[]
    new_tweets=api.GetSearch(search_string,count=100,result_type="recent")
    alltweets.extend(new_tweets)

I get a bunch of tweets as a result. 结果,我收到了一堆推文。 However, when I find the location of user that has tweeted it using: 但是,当我找到使用以下信息发布推文的用户的位置时:

    p=api.GetUser(user_id=id)
    print p.location

The location turned out to be different in many cases(It is the location that we update in the profile) . 在很多情况下,位置都不同(这是我们在配置文件中更新的位置)。 I wanted to know, when we search for tweets with a particular string using "place:place_id", what location does twitter take? 我想知道,当我们使用“ place:place_id”搜索带有特定字符串的推文时,twitter会位于哪个位置? Is it where the user is while tweeting the tweet or the location that we provide in our profile? 是用户在发推文时所在的位置,还是我们在个人资料中提供的位置?

When you use place: it is the location of a user when they posted the tweet. 使用地点时:用户发布推文时的位置。 In your case the results will either be Mumbai or a more specific place inside Mumbai, such as a neighborhood. 在您的情况下,结果将是孟买,或者是孟买内部更特定的地方,例如邻居。

$ oksocial 'https://api.twitter.com/1.1/search/tweets.json?q=place%3A7929cea6bd5b32bd' | jq '.statuses[].place.full_name'
"Mumbai, India"
"Mumbai, India"
"Mumbai, India"
"Mumbai, India"
"Mumbai, India"
"Mumbai, India"

San Francisco 旧金山

$ oksocial 'https://api.twitter.com/1.1/search/tweets.json?q=place%3A5122804691e5fecc' | jq '.statuses[].place.full_name'
"Emeryville, CA"
"San Francisco, CA"
"South Beach, San Francisco"
"San Francisco, CA"
"San Francisco, CA"
"Oakland, CA"
"San Jose, CA"
"Fremont, CA"
"Richmond, CA"
"San Leandro, CA"

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

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