为什么这两个API(Twitter地理/搜索API)返回不同的结果集?

4

我正在获取一个特定区域的推文,但是得到了非常不同的结果集。第一种方法是通过给出给定半径内的经度和纬度来实现的。这些经度和纬度在城市(Lahore,PK)内,并绘制了5公里的半径。5公里只是该城市的很小一部分。通过这种方法,我获取了一天内约60,000条推文。

方法1

import tweepy
consumer_key= 'xxxxxxxxxxxxxx'
consumer_secret= 'xxxxxxxxxxxxx'
access_token='xxxxxxxxxxxxxxx'
access_token_secret='xxxxxxxxxxxxxxxxxxxx'
api = tweepy.API(auth,wait_on_rate_limit = Truewait_on_rate_limit_notify= True)
public_tweets = tweepy.Cursor(api.search, count=100, geocode="31.578871,74.305184,5km",since="2018-06-09",show_user = True,tweet_mode="extended").items()
for tweet in public_tweets:
    print(tweet.full_text)

第二种方法,我使用了Twitter地理搜索API,通过查询拉合尔(granularity="city"),现在我正在获取整个城市的推文。但是现在我只能得到一天中1200条推文。我还从过去7天中获取了15000条推文,这是一个非常大的差异,整个城市只给了我1200条推文,而同一城市的小部分却给了我超过60000条推文。我还打印了场所ID以验证我是否获得了准确的多边形。这些是多边形( 74.4493870, 31.4512220 74.4493870, 31.6124170 74.2675860, 31.6124170 74.2675860, 31.4512220),我在https://www.keene.edu/上进行了绘制以验证。是的,这些是拉合尔市的准确多边形。
import tweepy
consumer_key= 'xxxxxxxxxxxxxx'
consumer_secret= 'xxxxxxxxxxxxx'
access_token='xxxxxxxxxxxxxxx'
access_token_secret='xxxxxxxxxxxxxxxxxxxx'
api = tweepy.API(auth,wait_on_rate_limit = Truewait_on_rate_limit_notify= True)

places = api.geo_search(query="Lahore", granularity="city")

for place in places:    
    print("placeid:%s" % place)
public_tweets = tweepy.Cursor(api.search, count=100,q="place:%s" % place.id,since="2018-06-09",show_user = True,tweet_mode="extended").items()
for tweet in public_tweets:
    print(tweet.full_text)

现在请您先告诉我,为什么结果会有如此大的差异。我正在使用标准的API版本。
其次,请告诉我这些API是如何获取推文的。因为少于1%的推文带有地理标记,并且也不是每个用户在他们的个人资料中都准确地注明了城市和国家。一些用户会提到像火星和地球这样的事物。那么这些API是如何工作以在特定区域内获取推文的呢?它们是通过在半径范围内搜索或查询城市/国家来实现的吗?我研究了Twitter API文档和Tweepy文档,以了解这些API是如何在后台收集特定区域的推文的,但我没有找到任何有用的材料。
1个回答

3
第一种方法有更多结果的原因是,如果推文没有任何地理信息,则使用geocode搜索将会退回到配置文件(正如您已经猜到的那样),并尝试将其解析为纬度/经度。
请参阅此处的文档:

https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators.html

地理定位:API 中没有“near”搜索运算符,但是可以使用指定了模板“纬度、经度、半径”的 geocode 参数更精确地限制查询位置,例如,“37.781157,-122.398720,1mi”。在进行地理搜索时,搜索 API 会首先尝试查找具有查询 geocode 范围内的纬度/经度的推文,如果没有成功,则会尝试查找其个人资料位置可以反向地编码为查询 geocode 范围内的纬度/经度的用户创建的推文,这意味着可能会收到不包括纬度/经度信息的推文。

另一方面,使用 place_id 进行搜索似乎正在寻找确切的位置。以下是基本的 API 调用语法: https://developer.twitter.com/en/docs/tweets/search/guides/tweets-by-place

与 geocode 中的纬度/经度不同,place API 的工作方式非常不同。下一页介绍了可以与推文关联的两种类型的位置数据之间的差异:

https://developer.twitter.com/en/docs/tutorials/filtering-tweets-by-location

Tweet-specific location information falls into two general categories:

Tweets with a specific latitude/longitude “Point” coordinate
Tweets with a Twitter “Place” (see our blog post on Twitter Places: More Context For Your Tweets and our documentation on Twitter

geo objects for more information).

...

Tweets with a Twitter “Place” contain a polygon, consisting of 4 lon-lat coordinates that define the general area (the “Place”) from which the user is posting the Tweet. Additionally, the Place will have a display name, type (e.g. city, neighborhood), and country code corresponding to the country where the Place is located, among other fields.

此外,这个部分要注意复数用法Place IDs

地点:

通过名称或ID过滤特定的地点。要发现与特定区域相关的“地点”,请在REST API中使用Twitter的reverse_geocode端点。然后使用您找到的地点ID与place:操作符一起跟踪包括对特定地点的引用的推文。如果您使用地点名称而不是数字ID,请确保引用任何包含空格或标点符号的名称。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接