Tweepy 地理位置搜索不返回结果
Tweepy Geolocation Search Not Returning Results
我从这里的其他几篇文章中提取了这段代码,重点关注在特定地理区域搜索推文的主题。不幸的是,我从这段代码中收到的只是一个空白的电子表格。我尝试了几次不同的迭代,添加了额外的参数但无济于事。我在这里遗漏了什么吗?
import tweepy
import csv
consumer_key = 'XXXXX'
consumer_secret = 'XXXXX'
access_token = 'XXXXX'
access_token_secret = 'XXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
search_area = tweepy.Cursor(api.search, count=100, geocode="37.5407,77.4360,5km").items()
output = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8"), tweet.favorite_count, tweet.retweet_count,
tweet.entities.get('hashtags'), tweet.entities.get('user_mentions'), tweet.entities.get('media'),
tweet.entities.get('urls')] for tweet in search_area]
with open('city_tweets.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(["id", "created_at", "text", "likes", "retweets", "hashtags",
"user mentions", "media", "links"])
writer.writerows(output)
37.5407、77.4360是37°32'26.5"N 77°26'09.6"E,在中国西部比较人烟稀少的地方,推特被封了,所以最近一周没有推文也是有道理的。
您是说 37.5407,-77.4360 吗?它几乎就是弗吉尼亚州里士满的中心。
我从这里的其他几篇文章中提取了这段代码,重点关注在特定地理区域搜索推文的主题。不幸的是,我从这段代码中收到的只是一个空白的电子表格。我尝试了几次不同的迭代,添加了额外的参数但无济于事。我在这里遗漏了什么吗?
import tweepy
import csv
consumer_key = 'XXXXX'
consumer_secret = 'XXXXX'
access_token = 'XXXXX'
access_token_secret = 'XXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
search_area = tweepy.Cursor(api.search, count=100, geocode="37.5407,77.4360,5km").items()
output = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8"), tweet.favorite_count, tweet.retweet_count,
tweet.entities.get('hashtags'), tweet.entities.get('user_mentions'), tweet.entities.get('media'),
tweet.entities.get('urls')] for tweet in search_area]
with open('city_tweets.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(["id", "created_at", "text", "likes", "retweets", "hashtags",
"user mentions", "media", "links"])
writer.writerows(output)
37.5407、77.4360是37°32'26.5"N 77°26'09.6"E,在中国西部比较人烟稀少的地方,推特被封了,所以最近一周没有推文也是有道理的。
您是说 37.5407,-77.4360 吗?它几乎就是弗吉尼亚州里士满的中心。