简体   繁体   English

如何通过tweepy获取Twitter用户的位置?

[英]How to get twitter user's location with tweepy?

I am starting to make a python program to get user locations, I've never worked with the twitter API and I've looked at the documentation but I don't understand much. 我开始制作一个python程序来获取用户位置,我从来没有使用过twitter API,我看过文档,但我不太了解。 I'm using tweepy, can anyone tell me how I can do this? 我正在使用tweepy,任何人都可以告诉我如何做到这一点? I've got the basics down, I found a project on github on how to download a user's tweets and I understand most of it. 我已经掌握了基础知识,我在github上找到了一个关于如何下载用户推文的项目,我对其中的大部分内容都了如指掌。

Once you have the twitter (JSON) search results, you can extract the location information, if it's available. 获得推特(JSON)搜索结果后,您可以提取位置信息(如果可用)。 Not all twitter users have included their location information. 并非所有Twitter用户都包含他们的位置信息。

for tweet in results:
    print(tweet.get('user', {}).get('location', {}))

After analyzing the twitter API responses for various queries, I think getting the tweet location is not possible since the API does not include it in the JSON response. 在分析各种查询的twitter API响应之后,我认为获取推文位置是不可能的,因为API不包含在JSON响应中。

Once you have a tweet, the tweet includes a user, which belongs to the user model. 一旦你有推文,推文就会包含一个属于用户模型的用户。 To call the location just do the following 要呼叫该位置,请执行以下操作

tweet.user.location tweet.user.location

I don't believe that Tweepy can get user location data; 我不相信Tweepy可以获得用户位置数据; have you had a look the documentation ? 你有看看文件吗?

You may be better off with Twython which can call the get statuses/user_timeline API call? 使用Twython可能会更好,可以调用get statuses / user_timeline API调用吗?

Also bear in mind that for privacy reasons twitter won't give you a lat/long for users; 另外请记住,出于隐私原因, Twitter不会为用户提供lat / long; the user has their location made less accurate, usually referencing their "neighborhood". 用户的位置不太准确,通常引用他们的“邻居”。

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

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