#importing all dependencies
import numpy as np
import tweepy
import requests
import base64
import ssl

ssl._create_default_https_context = ssl._create_unverified_context

#Test Bot Auth Keys
consumer_key = ‘’ # api key
consumer_secret = ‘’ # api passw
key = ‘’ # consumer key
secret = ‘’ # consumer password

Authentication with Twitter

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth)

img = “home/yo/image.jpeg”
api.update_with_media(img, status=“yo”)

So I have figured out how to post images to Twitter through a local file path, but ideally I would like to be able to post the image through a web link such as a “web url” (I can’t post a web link). Is there a way to direct the file path to a url like this and have the twitter post the image in my tweet? I noticed if I just post the url it doesn’t convert it to an image, it just tweets the web link. If I can’t do this, how can I access a photo from something like Google cloud in my img file path remotely?

  • List item
1 Like

No, you will have to download the image file yourself and upload the bytes - the API doesn’t accept anything else.

If I have the images on google drive, can I use the image fro there?

No, not unless you read the files themselves somehow and send the bytes to the API, not any urls.

What would be the best approach to randomly grabbing from a group of these images in the drive?

This is probably a better question for stackoverflow.com and the Google Drive API: How to randomly download many files from a google drive folder - Stack Overflow