Search code examples
pythonapitwitterbotstweepy

Tweepy error: code: 261 Application cannot perform write actions. How to work around this?


I was just trying to create a bot that uploads a tweet after a time interval (not necessarily regular). However, after a certain amount of tweets my app gets limited and restricted by twitter. Is there a work around for this? The max number of tweets I've been able to send has been 30. I even tried using sleep() with random time limits but it still doesn't work.

import tweepy
import random
import time

consumerKey=''
consumerSecret=''
accessToken=''
accessTokenSec=''

def OAuth():
    try:
        auth=tweepy.OAuthHandler(consumerKey,consumerSecret)
        auth.set_access_token(accessToken,accessTokenSec)
        return auth
        
    except Exception as e:
        return None

oauth=OAuth()
api=tweepy.API(oauth,wait_on_rate_limit=True)

tweets=['i love roses','7 is my favourite number', 'Studies are hard','Guess how many donuts I just ate','A cat ran over my foot']

for i in range(40):
    num2=random.randint(0,4)
    randtime=random.randint(60,120)
    api.update_with_media(imglink,+tweets[num2])
    print("status uploaded")
    time.sleep(randtime)

Solution

  • Same problem, unfortunately Twitter API have restrictions for normal users. You need to are a company or something else. Twitter need to know how you use the data. There is no way sorry...