コンテンツへスキップ

PythonでTwitter完全自動化!つぶやきもリプも投稿も一括操作!

https://developer.x.com/en

pip install tweepy
import tweepy
import schedule
import time

# Twitter APIの認証情報
consumer_key = ‘YOUR_CONSUMER_KEY’
consumer_secret = ‘YOUR_CONSUMER_SECRET’
access_token = ‘YOUR_ACCESS_TOKEN’
access_token_secret = ‘YOUR_ACCESS_TOKEN_SECRET’

# 認証処理
auth = tweepy.OAuth1UserHandler(consumer_key, consumer_secret, access_token, access_token_secret)
api = tweepy.API(auth)

# ツイートを投稿する関数
def tweet():
api.update_status(“こんにちは!Pythonで自動投稿しています。 #Python #Tweepy”)

# 毎日12:00にツイートを投稿するスケジュールを設定
schedule.every().day.at(“12:00”).do(tweet)

# スケジュールを実行し続けるループ
while True:
schedule.run_pending()
time.sleep(60) # 1分ごとにチェック

import tweepy

# TwitterのAPIキーとAPIシークレットを入力
consumer_key = ‘YOUR_CONSUMER_KEY’
consumer_secret = ‘YOUR_CONSUMER_SECRET’
access_token = ‘YOUR_ACCESS_TOKEN’
access_token_secret = ‘YOUR_ACCESS_TOKEN_SECRET’

#認証処理
auth = tweepy.OAuth1UserHandler(consumer_key, consumer_secret, access_token, access_token_secret)
api = tweepy.API(auth)
#認証確認
try:
api.verify_credentials()
print(“認証成功”)
except:
print(“認証失敗”)

# 特定のユーザーの最新ツイートを取得
tweets = api.user_timeline(screen_name=’こーちゃん’, count=5)

# ツイート内容を表示
for tweet in tweets:
print(f”{tweet.user.name} said: {tweet.text}”)

Facebooktwittermail

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA