How to send public tweets with image attached?
See original GitHub issue❓ Question
I’m in the process converting my app, that currently uses twurl
to send out tweets like this, into using apprise
because of its broad support for notification channels. My tweets are public, have a body text and attach an image. I obviously already have Twitter creds to be able to do this.
Currently, using twurl
, this is a 2 step process (see example in bash
script below) that works reliably:
- first upload the image and receive a json object that contains an Media ID
- then send a tweet with body text that references the Media ID
# upload the image and get a Media ID:
TW_MEDIA_ID=$(twurl -X POST -H upload.twitter.com "/1.1/media/upload.json" -f /tmp/snapshot.png -F media | sed -n 's/.*\"media_id\":\([0-9]*\).*/\1/p')
# Send a tweet and reference the Media ID to be used
LINK=$(echo `twurl -r "status=$TWEETTEXT&media_ids=$TW_MEDIA_ID" /1.1/statuses/update.json` | tee -a /tmp/tweets.log | jq '.entities."urls" | .[] | .url' | tr -d '\"')
# LINK now contains the URL of the tweet
Switching to apprise
, I an able to successfully send tweets without images and I’m grateful to no longer have to make my body text html-safe:
apprise -b "$TWEETTEXT" twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet
Attempt 1: I tried adding the media ID and body in a single request using apprise
: didn’t work
apprise -a file:///tmp/snapshot.png -b "$TWEET" twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet
Attempt 2: I tried to upload the file attachment without body, and apprise
complained of not having any text in the body
apprise -a file:///tmp/snapshot.png twitter://$TWITTER_CONSKEY/$TWITTER_CONSSECRET/$TWITTER_ACCTOKEN/$TWITTER_ACCSECRET/?mode=tweet
Could someone help me with an example (command line would be fine) of how to do what I want? Generally, there’s a single PNG image that I have available as a file, and the text is curated to be of proper size for public tweeting.
Once I’m done with Twitter, my next target is Discord using a Webhook. Hopefully the Twitter answer will be analogous to what I need to do for Discord.
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (11 by maintainers)
Top GitHub Comments
Thanks so much for your efforts. I got sidetracked a bit with solving some performance bugs on my project, but I’m really looking forward to incorporate this. I will keep you updated on the progress and use of Apprise in my project.
thanks – that would be something that I’d greatly appreciate, as it’d a prerequisite for me to be able to switch to
apprise
. For the rest – this will make my life writing notifiers so much easier!When do you think this will be available? Weeks? Months?
About Twitter - you should understand that their terminology has changed a bit.