@yuutayaro

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Twitterの指定ユーザーのフォロワーをフォローしたい

解決したいこと

Twitterの指定ユーザーのフォロワーをフォローしたい

PythonとTwitter APIを使用し上記の挙動をするプログラムを作ろうとしております。
ですがエラーが起きてしまうので解決方法を教えてください。
また下記のソースコードでやりたいことは出来る認識ですが足りないものがあれば教えてください。
つたない質問の仕方ではありますが宜しくお願い致します。

参考にしたソース
https://note.com/analoggamer/n/n16a88f3805af#JH9qn

発生している問題・エラー

 File "d:\ダウンロード\python\フォロワー欄フォロー取得\test.py", line 16, in <module>
    follower_ids = pd.Series(api.followers_ids())
  File "C:\python\lib\site-packages\tweepy\binder.py", line 253, in _call
    return method.execute()
  File "C:\python\lib\site-packages\tweepy\binder.py", line 234, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 215, 'message': 'Bad Authentication data.'}]

該当するソースコード

import tweepy
import pandas as pd
from tweepy import api

def get_twitter_api():
   API_key = "設定済"
   API_secret = "設定済"
   Access_token ="設定済"
   Access_secret = "設定済"
   screen_name = "設定済"
   auth = tweepy.OAuthHandler(API_key, API_secret)
   auth.set_access_token(Access_token, Access_secret)
   api = tweepy.API(auth, wait_on_rate_limit = True)
   return api,screen_name

follower_ids = pd.Series(api.followers_ids())

follower_dic = {}
for index,follower_ids in enumerate(follower_ids):
   print(index)
   try:
       user = api.get_user(id = follower_ids)
   except tweepy.error.TweepError as e:
       print(e)
   follower_dic[user.screen_name] = user.description
df = pd.DataFrame(follower_dic.values(),index = follower_dic.keys()).reset_index()
df.columns= ["screen_name","profile"]

def follows(api,follower_ids):
    target = api.get_user(id = follower_ids)
    followCount = 0

    if target.protected == False and followCount<100 :
        try:
            api.create_friendship(follower_ids)
            followCount = followCount+1
            print("follow" + str(follower_ids))
        except:
            print("Follow error" + str(follower_ids))


例)

def greet
  puts Hello World
end

自分で試したこと

API KEYとaccess tokenの再発行で解決したと記載があったので
再発行をしてみました。

参考
https://teratail.com/questions/236548

0 likes

1Answer

get_twitter_api が実行されていないようです...

名前空間を意識されると良いかと思います><

0Like

Your answer might help someone💌