尝试使用 tweepy 创建推文

问题描述 投票:0回答:0

正如标题中所说,我试图用机器人唱 tweepy 来创建推文,但我不断收到错误。请记住,我有 0 编码经验,并且我仅依赖网站上的各种指南。 蟒蛇3 APIv2

这是我的代码:

from typing import Self
import tweepy
CONSUMER_KEY = "XXXXX"
CONSUMER_SECRET = "XXXXX"
ACCESS_TOKEN = "XXXXX"
ACCESS_SECRET = "XXXXX"
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)

api = tweepy.Client(access_token=ACCESS_TOKEN,
                    access_token_secret=ACCESS_SECRET,
                    consumer_key=CONSUMER_KEY,
                    consumer_secret=CONSUMER_SECRET)
try:
    api.verify_credentials()
    print("Authentication Successful")
except:
    print("Authentication Error")

filename=open('content.txt.txt')

f=filename.readlines()

filename.close()
for line in f:
 try:
  tweepy.Client.create_tweet(Self, text = line, user_auth=True)
  print(line)
 except tweepy.errors.TweepyException as err:
   print("err")

这是我得到的错误(Windows 终端):

PS C:\bot> python app.py
Authentication Error
Traceback (most recent call last):
  File "C:\bot\app.py", line 28, in <module>
    tweepy.Client.create_tweet(Self, text = line, user_auth=True)
  File "C:\Users\totes\AppData\Local\Programs\Python\Python311\Lib\site-packages\tweepy\client.py", line 835, in create_tweet
    return self._make_request(
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\totes\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 450, in __getattr__
    raise AttributeError(item)
AttributeError: _make_request
python twitter tweepy twitter-api-v2
© www.soinside.com 2019 - 2024. All rights reserved.