标签: tweepy

如何使用Python检索给定用户的所有推文和属性?

我正在尝试从Twitter检索数据,使用Tweepy获取在命令行输入的用户名.我想提取有关状态和用户的相当多的数据,所以提出以下内容:

请注意,我正在导入所有必需的模块,并且有oauth +键(这里没有包含它),文件名是正确的,只是更改了:

# define user to get tweets for. accepts input from user
user = tweepy.api.get_user(input("Please enter the twitter username: "))

# Display basic details for twitter user name
print (" ")
print ("Basic information for", user.name)
print ("Screen Name:", user.screen_name)
print ("Name: ", user.name)
print ("Twitter Unique ID: ", user.id)
print ("Account created at: ", user.created_at)

timeline = api.user_timeline(screen_name=user, include_rts=True, count=100)
    for tweet in timeline:
        print ("ID:", tweet.id)
        print ("User ID:", tweet.user.id)
        print ("Text:", tweet.text)
        print ("Created:", tweet.created_at) …
Run Code Online (Sandbox Code Playgroud)

python twitter oauth tweepy

11
推荐指数
2
解决办法
2万
查看次数

使用Tweepy在Python中获取关注者列表的最佳方法

有没有比使用Tweepy更好的方法来获取关注者屏幕名称列表:

for follower in api.followers_ids('twitter'):
    print api.get_user(follower).screen_name
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy

11
推荐指数
1
解决办法
1万
查看次数

Tweepy:ImportError:无法导入名称Random

我正在使用Tweepy向Twitter发送一些消息.我从API获得了很长的追溯.回溯定于:

ImportError: cannot import name Random
Run Code Online (Sandbox Code Playgroud)

我使用Pip安装最新版本的Tweepy:

Name: tweepy
Version: 2.3.0
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires:
Run Code Online (Sandbox Code Playgroud)

我打电话的时候

import tweepy
Run Code Online (Sandbox Code Playgroud)

我得到这个追溯:

Traceback (most recent call last):
  File "/Users/dromard/Projects/Drop Playlist/drop.py", line 4, in <module>
    import tweepy
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/__init__.py", line 14, in <module>
    from tweepy.api import API
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/api.py", line 8, in <module>
    from tweepy.binder import bind_api
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 5, in <module>
    import httplib
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module>
    import mimetools
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, …
Run Code Online (Sandbox Code Playgroud)

tweepy python-2.7

11
推荐指数
1
解决办法
1万
查看次数

如何使用图像url在tweepy中更新twitter状态?

这是我用过的代码,

#Twitter credentials
access_token = config.get('twitter_credentials', 'access_token')
access_token_secret = config.get('twitter_credentials', 'access_token_secret')
consumer_key = config.get('twitter_credentials', 'consumer_key')
consumer_secret = config.get('twitter_credentials', 'consumer_secret')

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = API(auth)

img = "http://animalia-life.com/data_images/bird/bird1.jpg"
api.update_with_media(img, status="Nice one")
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误

No such file or directory
Run Code Online (Sandbox Code Playgroud)

我知道我必须使用上面的命令使用本地目录中的文件.有没有办法在使用update_with_media时使用URL?

python twitter tweepy

11
推荐指数
1
解决办法
9807
查看次数

通过推文位置和用户位置来抓取推文

我试图使用tweepy使用推文位置下载推文而不是用户位置.目前,我可以使用用户位置下载推文,但即使geo_enabled返回True 也无法获取推文位置.

例如,假设user_a来自纽约,但他来自加利福尼亚的推文.我想要用户位置,纽约和推文位置,加利福尼亚州.

码:

import tweepy
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import pandas as pd
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf8')

ckey = 'key'
csecret = 'secret'
atoken = 'token'
asecret = 'secret'
#csvfile = open('StreamSearch.csv','a')
#csvwriter = csv.writer(csvfile, delimiter = ',')

class StdOutListener(StreamListener):
    def __init__(self, api=None):
        super(StdOutListener, self).__init__()
        self.num_tweets = 0

    def on_data(self, data):
        self.num_tweets += 1
        if self.num_tweets < 5: #Remove the limit of no. …
Run Code Online (Sandbox Code Playgroud)

python twitter geolocation tweepy

11
推荐指数
1
解决办法
6766
查看次数

Heroku - 没有正在运行的Web进程

我在Python中使用tweepy创建了一个twitter机器人,并尝试使用Heroku进行部署.Bot只是在一定间隔后发推文.部署之后,Python程序就不运行了,Heroku日志显示以下错误:

at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=fathomless-island-25537.herokuapp.com request_id=0aa76d12-31e6-4940-85ec-a8476af4f82f fwd="182.64.210.145" dyno= connect= service= status=503 bytes=
Run Code Online (Sandbox Code Playgroud)

在查看了必须部署django应用程序的类似问题之后,我尝试了:

heroku ps:scale web=1
Run Code Online (Sandbox Code Playgroud)

得到了:

Scaling dynos... !
 !  Couldn't find that formation.
Run Code Online (Sandbox Code Playgroud)

这是否意味着该程序未能建立网络流程或是否存在与dynos相关的其他内容?或者,如果我必须在我的程序中包含一些与dynos相关的代码?我不知道整个过程的哪个部分有问题.道歉,如果它太基础了.

python heroku tweepy python-3.x

11
推荐指数
2
解决办法
1万
查看次数

Twitter Streaming API - urllib3.exceptions.ProtocolError: ('连接中断:IncompleteRead

使用 tweepy 运行 python 脚本,该脚本在英语推文的随机样本中流式传输(使用 twitter 流 API)一分钟,然后交替搜索(使用 twitter 搜索 API)一分钟,然后返回。我发现的问题是,大约 40 秒后,流媒体崩溃并出现以下错误:

完整错误:

urllib3.exceptions.ProtocolError: ('连接中断:IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

读取的字节数可以在 0 到 1000 之间变化。

第一次看到流过早中断,搜索功能提前启动,搜索功能完成后,它再次返回流,第二次再次出现此错误时,代码崩溃。

我正在运行的代码是:

# Handles date time calculation
def calculateTweetDateTime(tweet):
    tweetDateTime = str(tweet.created_at)

    tweetDateTime = ciso8601.parse_datetime(tweetDateTime)
    time.mktime(tweetDateTime.timetuple())
    return tweetDateTime

# Checks to see whether that permitted time has past.
def hasTimeThresholdPast():
    global startTime
    if time.clock() - startTime > 60:
        return True
    else:
        return False

#override tweepy.StreamListener to add logic to on_status
class StreamListener(StreamListener):

    def on_status(self, …
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy twitter-streaming-api

11
推荐指数
1
解决办法
4240
查看次数

无法导入 StreamListener

我正在尝试使用 Twitter API 在 Python 中创建数据流,但无法StreamListener正确导入。

这是我的代码:

import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener

class MyListener(StreamListener):
 
    def on_data(self, data):
        try:
            with open('python.json', 'a') as f:
                f.write(data)
                return True
        except BaseException as e:
            print("Error on_data: %s" % str(e))
        return True
 
    def on_error(self, status):
        print(status)
        return True
 
twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=['#python'])
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Traceback (most recent call last):
  File "c:\Users\User\Documents\GitHub\tempCodeRunnerFile.python", line 6, in <module>
    from tweepy.streaming import StreamListener
ImportError: cannot import name 'StreamListener' from 'tweepy.streaming' (C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\tweepy\streaming.py)
Run Code Online (Sandbox Code Playgroud)

python api twitter import tweepy

11
推荐指数
2
解决办法
2万
查看次数

通过Tweepy在Twitter上更新状态时的回溯

我一直试图在Twitter上使用我的Rpi发布读数tweepy,但首先我想检查一下是否tweepy正常工作,但事实并非如此.

我正确地安装了软件包,但是当我尝试运行一个简单的代码来发布一些东西时,我收到了一个错误(是的,我已经创建了一个应用程序并拥有4个凭据).

我正在尝试运行的代码:

import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
single_tweet = 'hello world'
api.update_status(single_tweet)
print "successfully Updated"
Run Code Online (Sandbox Code Playgroud)

我懂了:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
  File "build/bdist.linux-armv6l/egg/tweepy/api.py", line 193, in update_status
  File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 239, in _call
  File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 223, in execute
tweepy.error.TweepError: [{u'message': u'media_ids parameter is invalid.', u'code': 44}]
Run Code Online (Sandbox Code Playgroud)

我正在运行在tweepy文件夹"oauth.py"中的python代码(添加我的凭据)

$ sudo python …
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy

10
推荐指数
1
解决办法
2958
查看次数

主脚本停止时后台进程的参数错误无效

我有这个代码通过运行后台进程来获取推文.以下脚本使用subprocess.Popen函数从主脚本运行.这样主脚本将在调用后台进程脚本后停止执行.

def start_listner(unique_id, keyword, limit=200):
    class CustomStreamListener(tweepy.StreamListener):

        def __init__(self, api):
            logger.info('runnning')
            self.api = api
            super(tweepy.StreamListener, self).__init__()

            #setup rabbitMQ Connection


        def on_status(self, status):
            print status.text.encode('utf-8'), "\n"
            #queue the tweet and writes the tweet to the log

        def on_error(self, status_code):
          #some code to not kill the stream

        def on_timeout(self):
          #some code to not kill the stream

    sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api))
    try:
        logger.info('tracking started')
        logger.info(keyword)
        logger.info(type(keyword))
        kw = keyword
        sapi.filter(track=[kw])  # keeps listening to the streaming api
    except Exception, err:
        logger.info(kw) …
Run Code Online (Sandbox Code Playgroud)

python daemon background-process tweepy python-2.7

10
推荐指数
1
解决办法
565
查看次数