我是Stack OverFlow的新手,对python来说还是新手。下载Tweepy并使用它搜索关键字的基本功能后,我想扩展并搜索基于特定地理位置的地理标记推文。我找到了几个脚本示例,但没有成功地让它们工作。我的问题是,你是否看到包含脚本语法的任何问题?出于某种原因,我无法让它发挥作用。我不断在print语句中得到错误" print tweet.id。" 提前致谢!
from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import tweepy
consumer_key="###########################"
consumer_secret="###############################"
access_token="#######################################"
access_token_secret="###################################"
def searchTweets():
#39.95556,-75.164,4mi = Phillaelphia Location with a 4 miles radius
tweet = api.search(q="",geocode="39.95256,-75.164,4mi",count=25)
for tweet in tweets:
if tweet.geo:
print tweet.id
print tweet.geo
print tweet.text
class Listener(tweepy.StreamListener):
def on_status(self,status):
print “screen_name=’%s’ tweet=’%s’ text=’%s’” (status.author.screen_name, status.coordinates, status.text)
streaming_api = tweepy.streaming.Stream(auth, Listener(), timeout=60)
# Phillaelphia Location
streaming_api.filter(follow=None, locations=[-75.4043,39.896,-75.0503,40.161])`