爲什麼我得到這個錯誤?這裏是我如何調用流媒體API。Twitter上的GAE流式傳輸
import tweepy
import sys
creds = json.loads(open('credential.json').read())
tw_consumer_key = creds['tw_consumer_key']
tw_consumer_secret = creds['tw_consumer_secret']
tw_access_token = creds['tw_access_token']
tw_access_token_secret = creds['tw_access_token_secret']
try:
auth = tweepy.OAuthHandler(tw_consumer_key, tw_consumer_secret)
auth.set_access_token(tw_access_token, tw_access_token_secret)
api = tweepy.API(auth)
except Exception:
service = None
api = None
# Query terms
Q = "Better"
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
try:
print "%s\n%s\n%s\n%s\n\n" % (status.text,
status.author.screen_name,
status.created_at,
status.source,)
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
class LiveStream(webapp2.RequestHandler):
def get(self):
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
self.response.out.write(streaming_api.filter(track=Q))
大概到GAE引起不容許的插座,我不知道如何申請查詢檢索詞來獲得特定的過濾流的鳴叫。我使用這部分代碼的目的是通過指定關鍵字實現直播。如果有其他方法,請指導。
有人說Google不允許我們在GAE中使用套接字,有沒有別的方法可以用例子來指導。謝謝 – 1myb