I want to use Twitter APi to create images.

Problems/Error messages i am experiencing

I made a code that tweeted the image, but the process ended with a status of 200 (no error occurred) and nothing was tweeted.

source code:
# tweet with image
from requests_oauthlib import OAuth1Session
from API_Study import personal_information as inf
# twitter contribution URL
url = "https://api.twitter.com/1.1/statuses/update.json"
url_media = "https://upload.twitter.com/1.1/media/upload.json"
# twitter context
files = {"status": "Hello, World! afa", "media": open ("image/test.png", "rb")}
#OAuth contribution with POST method
#CK Consumer Key
#CS Consumer Secret
#AT access token
#AS Access token secret
twitter = OAuth1Session (inf.CK, inf.CS, inf.AT, inf.AS)
req = twitter.post (url_media, files = files)
# respons confirmation
if req.status_code == 200:
    print ("OK")
    print ("Error:" + str (req.status_code))

I have already made a splash through the API.
I tried reading the Twitter API reference, but I don't know how to read it.

  • Answer # 1

    It is recommended to use tweepy and python-twitter libraries unless otherwise noted.

    How to post a Tweet with an image

    /media/upload.jsonpostand get the image ID (media_id) as a return value

    For/statuses/update.json,statusand the image ID obtained in step 1 arepost

    If you poststatuswith the same sentence as the previous Tweet as a caution forstatuses Please do not post the same content by putting a single-byte space at the end.

    ◇ Reference information
    Python Twitter post