I'm trying to make a twitterbot that takes and posts pictures. I just ran my program, and it worked, but didn't when I ran it again. I tried a couple more times, stepped away from the computer for a few minutes, and when I came back it worked! But now, it's not posting again. I have not edited the code at all. I have some lines I want to remove because I don't think I need them, but I can't test that when the program seemly runs fine with or without them (no error codes in the shell) but posts nothing either way. Here's what I've got:
#imports
from picamera import PiCamera
from time import sleep
from datetime import datetime
import sys
import os
import pygame
import pygame.camera
from pygame.locals import *
from twython import Twython
twitter = Twython()
#timestamping
timestamp = datetime.now().isoformat() #creates timestamp
photo_path = '/home/pi/KittyTweeting/Photos/%s.jpg' % (timestamp) #creates filename for photo
#Camera
camera = PiCamera()
camera.start_preview() #shows picture preview on-screen when running on PC
sleep(1)
camera.capture(photo_path) #takes and saves photo
camera.stop_preview() #ends preview
#Tweeting
tweetStr = "Help" #sets string to be tweeted with image
apiKey = 'removed for posting'
apiSecret = 'removed for posting'
accessToken = 'Removed for posting'
accessTokenSecret = 'Removed for posting'
api = Twython(apiKey,apiSecret,accessToken,accessTokenSecret) #allows communication with Twitter
photo = open(photo_path, 'rb')
api.upload_media(media=photo, status=tweetStr) #posts tweet
#print "Tweeted: " + tweetStr
Is there something wrong with my code? Or does Twitter just have some kind of image posting rule that's stopping me? Thanks!
Yes, the Twitter API is rate limited:
The response to each API call will contain the following data about the rate limit for that particular API endpoint: