Tweepy-创建推文

发布于 2025-02-06 11:48:16 字数 288 浏览 2 评论 0原文

我正在尝试创建一个Twitter机器人,该机器人会在列表中鸣叫随机选择的文本。

当我使用client.create_tweet(text ='test')函数时,我会收到一条消息,说我缺少所需的位置参数'self'。据我了解,这种类型的错误是当您不初始化函数时会获得的错误,但是这些是斜纹中的预定义函数。我导入了访问令牌和秘密,以及API Secret and Key,当然,导入Tweepy

我想念什么吗?我应该将作为参数包括的self是什么?

I'm trying to create a twitter bot that would tweet a randomly selected text within a list.

When I use the Client.create_tweet(text='test') function, I get a message saying that I'm missing a required positional argument 'self'. From what I understand, this type of error is what you get when you don't initialized a function but those are predefined functions within Tweepy. I've imported access token and secret as well as api secret and key under, of course, import tweepy.

Am I missing something? What is the self that I should be including as parameter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2025-02-13 11:48:16

糟糕,这是一种创建带有曲折的推文的简单方法

以启动您需要创建客户端并插入自钥匙:

import tweepy

api=tweepy.Client(
    bearer_token='',
    consumer_key='',
    consumer_secret='',
    access_token='',
    access_token_secret='', 
)

之后,您可以使用付费捕获错误,如果有:

try:
    tweet=api.create_tweet(text='test',)
    print(tweet)

except Exception as error:
    print(error)

最后,现在,您可以运行PY文件

Oops, here's a simple way to create a tweet with tweepy

to start you need to create the Client and insert your self keys:

import tweepy

api=tweepy.Client(
    bearer_token='',
    consumer_key='',
    consumer_secret='',
    access_token='',
    access_token_secret='', 
)

after that you can use try pay catch errors if you have:

try:
    tweet=api.create_tweet(text='test',)
    print(tweet)

except Exception as error:
    print(error)

finally, now you can run the py file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文