有人可以告诉我如何在tweepy上从一个id获取一个用户名?我到处寻找,找不到任何东西.
我用tweepy写了一个推特程序.当我运行这段代码时,它会为它们输出Python ...值,比如
<tweepy.models.Status object at 0x95ff8cc>
Run Code Online (Sandbox Code Playgroud)
哪个不好.我如何获得实际的推文?
import tweepy, tweepy.api
key = XXXXX
sec = XXXXX
tok = XXXXX
tsec = XXXXX
auth = tweepy.OAuthHandler(key, sec)
auth.set_access_token(tok, tsec)
api = tweepy.API(auth)
pub = api.home_timeline()
for i in pub:
print str(i)
Run Code Online (Sandbox Code Playgroud) 我目前正在使用以下代码,这将获取推文,然后将其传递给处理的函数.但这不是实时的.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
mentions = api.mentions_timeline(count=1)
for mention in mentions:
processText()
Run Code Online (Sandbox Code Playgroud)
我也查看了流媒体推文,但我还没有找到一种方法来流式提及.
我试图使用Tweepy检索Twitter数据,使用下面的代码,但我返回401错误,我重新生成访问和秘密令牌,并出现相同的错误.
#imports
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#setting up the keys
consumer_key = 'xxxxxxx'
consumer_secret = 'xxxxxxxx'
access_token = 'xxxxxxxxxx'
access_secret = 'xxxxxxxxxxxxx'
class TweetListener(StreamListener):
# A listener handles tweets are the received from the stream.
#This is a basic listener that just prints received tweets to standard output
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
#printing all the tweets to the standard output
auth = OAuthHandler(consumer_key, consumer_secret) …Run Code Online (Sandbox Code Playgroud) 最终目标是使用tweepy api搜索专注于主题(即docker)和EXCLUDE转发.我已经看过提及不包括转推的其他主题,但它们完全适用.我试图将我学到的知识融入到下面的代码中,但我相信"如果不是"代码片段在错误的地方.任何帮助是极大的赞赏.
#!/usr/bin/python
import tweepy
import csv #Import csv
import os
# Consumer keys and access tokens, used for OAuth
consumer_key = 'MINE'
consumer_secret = 'MINE'
access_token = 'MINE'
access_token_secret = 'MINE'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('docker1.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
ids = set()
for tweet in tweepy.Cursor(api.search,
q="docker",
Since="2016-08-09",
#until="2014-02-15",
lang="en").items(5000000):
if not tweet['retweeted'] …Run Code Online (Sandbox Code Playgroud) 我刚开始使用tweepy开发一个小应用程序.
对于tweepy有什么有用的(和完整的)文档吗?
我用谷歌搜索,但没有找到任何东西.
我试图通过python和tweepy检索包含我个人twitter状态的全部内容的列表.
我已成功通过OAuth进行身份验证,但似乎无法从Twitter收到超过800个状态更新.我的Twitter生物页面说我有超过2000条推文.我完全符合Twitter对我们施加的3200条推文限制.
任何帮助将不胜感激!
这是我当前的代码(减去OAuth API身份验证):
for page in tweepy.Cursor(api.user_timeline, count=200).pages(16):
page_list.append(page)
n = n+1
print n
for page in page_list:
for status in page:
print status.text
Run Code Online (Sandbox Code Playgroud) 我希望能够跟踪包含某组词的推文,而不是其他推文.例如,如果我的过滤器是:"taco"AND("鸡"或"牛肉").
它应该返回这些推文:
-I am eating a chicken taco.
-I am eating a beef taco.
Run Code Online (Sandbox Code Playgroud)
它不应该返回这些推文:
-I am eating a taco.
-I am eating a pork taco.
Run Code Online (Sandbox Code Playgroud)
这是我目前正在运行的代码:
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import json
# authentication data- get this info from twitter after you create your application
ckey = '...' # consumer key, AKA API key
csecret = '...' # consumer secret, AKA API secret
atoken = '...' # access token …Run Code Online (Sandbox Code Playgroud) 我使用以下代码来流式传输我的Twitter帐户收到的邮件 - :
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy import API
from tweepy.streaming import StreamListener
# These values are appropriately filled in the code
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
class StdOutListener( StreamListener ):
def __init__( self ):
self.tweetCount = 0
def on_connect( self ):
print("Connection established!!")
def on_disconnect( self, notice ):
print("Connection lost!! : ", notice)
def on_data( self, status ):
print("Entered on_data()")
print(status, flush = True)
return True …Run Code Online (Sandbox Code Playgroud) 我正在使用Python的Tweepy库收集大量用户的信息.我的API初始化如下
api = tweepy.API(auth,wait_on_rate_limit = True,wait_on_rate_limit_notify = True)
auth包含我的令牌.此代码对速率限制错误响应良好,但不适用于其他一些错误.例如,我有时会看到以下异常.
Run Code Online (Sandbox Code Playgroud)tweepy.error.TweepError: [{'message': 'Over capacity', 'code': 130}]
我可以尝试使用try来处理此异常,但我想知道是否有办法在游标中处理此异常,就像我正在处理速率限制异常一样.我看到像retry_count这样的参数,但我不确定它们是否适用于这种情况,因为它们似乎是针对HTTP错误而设计的.