0

I am having an issue when trying to upload an image to twitter using a bash script and twurl. When I use a variable (which is storing the media_id of the image I want to upload) as the parameter for the "media_ids" that I appended to my status update, no photo gets posted and I receive this error message:

twurl -j -X POST -H upload.twitter.com "/1.1/media/upload.json" -f /root/$imgName -F media > mediaID.txt

local mediaID=$(egrep -o " [0-9]{19}" mediaID.txt)

twurl -X POST -H api.twitter.com "/1.1/statuses/update.json?status=The Astronomy Photo Of The Day (courtesy of NASA) for the day $date is \"$title\". For more details and info check out: https://apod.nasa.gov/apod/astropix.html&media_ids=$mediaID" | jq

“errors”: [ { “code”: 44, “message”: “media_ids parameter is invalid.” } ]

However, when I use the actual media_id value instead of the variable ($mediaID) of the image as the parameter for the "media_ids" that gets appended to the status update, everything works as expected.

Is there some issue with using a variable as a parameter for media_id? I am brand new to twurl and api's and therefore might be missing some basic point. I would really appreciate any help or suggestions on this topic. Thank you!

makoto
  • 23
  • 5
  • Is there meant to be a space before the 19 digits? I'm not sure if it is a "typo" but your egrep command is searching for a space and then 19 digits. Your mediaID variable will then be prefixed with a space and by the looks of the API documentation, there should be no spaces? – Raman Sailopal Dec 02 '20 at 17:52
  • If the space is intentional in the egrep command, use ${mediaID##" "} in the curl command – Raman Sailopal Dec 02 '20 at 18:01

0 Answers0