question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
kx1tcommented, Mar 8, 2022

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.

1reaction
kx1tcommented, Feb 12, 2022

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.

  • The Consumer Keys are now called “API Keys” and “API Secrets”, that are available under the Consumer Keys section.
  • “Access Key / Secret” is still called the same, but they fall now under “Authentication Tokens”. You need to make sure to create these with Read/Write/DM capabilities, otherwise Tweeting won’t work.
  • Additionally, Twitter is now tiering their access level, and you need to request “Elevated” access to be able to send Tweets through an API. This is free, but you need to write a short motivation.
Read more comments on GitHub >

github_iconTop Results From Across the Web

New in Sprout: Attach Images to Your Twitter Direct Messages
Attaching an image to a Direct Message from Sprout is easy. Whether replying to a DM from the Smart Inbox or initiating a...
Read more >
Here's How to Tweet a Link with a Preview Image on Twitter
Learn step-by-step how to tweet a link with a preview image on Twitter so you can generate more clicks to your website!
Read more >
Twitter - share button, but with image - Stack Overflow
Look into twitter cards. The trick is not in the button but rather the page you are sharing. Twitter Cards pull the image...
Read more >
How to: embed images in 'tweet this' links
If you cannot see the pic.twitter URL then try right-clicking on the tweet and selecting View source (or similar). Use CTRL+F to search...
Read more >
How to Reply on Twitter With a Picture
Click on the "Tweet" button to upload your picture and post your reply. Your followers can click on the "View Photo" link at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found