pythonのツイッターでフォローを行いたいのですが、エラー文がでてきてしまいます。
特定の文字列を含むツイートをリツイートするやつ
こちらの方が記載してくださったコードを参考に、フォローも追加したく追記したのですがエラーとなります。
import tweepy def api(): consumer_key = '××××' consumer_secret = '××××' access_key = '××××' access_secret = '××××' auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) return api dic = {} #辞書を定義しておきます。 for tweet in api().search('ツイート'): #エゴサ用の単語を入れます。 if tweet.retweeted == False: #リツイート”していない”ツイートだけを抽出。 text = tweet.text #ツイートのテキスト部分を変数textに代入。 id = tweet.id #ツイートの識別番号を変数idに代入 dic.update({id:text}) #変数textと変数idの紐付けをし、辞書dicに追加。 if '@' in dic[id]: #辞書dicにキーである変数idを代入し、テキスト本文を出力。@を含むツイート(リプライ)を除外。 pass else: api().create_friendship(id) api().create_favorite(id)
コードはRTのapi().retweet(id)をフォローのapi().create_friendship(id)に変えただけなのですが、下記のようなエラーがでてきてしまいます。
tweepy.error.TweepError: [{'code': 139, 'message': 'You have already favorited this status.'}]
api().create_friendship(id)に変更しなければスクリプト通りにちゃんと動いてくれるものなのですが、フォローを行う場合はどうするのが正しいのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。