简体   繁体   中英

Tweepy Geolocation Search Not Returning Results

I've pulled this code together from a few other posts on here focusing on the topic of searching for Tweets in a certain geographical area. Unfortunately, all I receive from this code is a blank spreadsheet. I have tried a few different iterations with additional parameters added to no avail. Is there something I am missing here?

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 is 37°32'26.5"N 77°26'09.6"E , which is in a relatively unpopulated area in Western China, where Twitter is blocked, so it makes sense for there to be no Tweets from there in the past week.

Did you mean 37.5407, -77.4360?, which is pretty much the center of Richmond, Virginia.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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