Share Image to Twitter without Card

Spread the love

Question Description

Given an image at a certain address, http://www.thissite.will/never/be-finished.png, what’s the easiest way to share it to Twitter, preferably without a card?


Users customize an SVG, and when they’re satisfied, I convert it to a PNG and store it on my server.

I want to give them the option of sharing the image on Twitter. They click on a button (which I can implement), and a dialog box opens, where they can add to the tweet (which should already contain the picture).

I know similar questions have been asked on this site before, but I do not want to use a “card” to share the image. Instead, I want a typical, non-card Tweet, just with an image (like this).

I’ve looked through the Twitter Developer Documentation repeatedly, but I can’t find helpful information. The POST statuses/update_with_media method is deprecated, and the link to the “Uploading Media Guide,” a suggested replacement, is broken. This guide, I assume, is what it intended to link to, but it has no JavaScript code to suggest how this should actually be implemented.

Please help.


My attempt, based off of POST media/upload:

$.ajax({
    url: "https://upload.twitter.com/1.1/media/upload.json", 
    format: "post", 
    data: {"data" : link}
}).success(function(response) {
    console.log(":)");
    console.log(response);
}).fail(function(response) {
    console.log(":(");
    console.log(response.responseText);
});

This fails. The responseText is {"errors":[{"code":215,"message":"Bad Authentication data."}]}.


Basically, I want to do something similar to what StackOverflow does. When you click “share” on a question, then select Twitter, a new window pops up populated with a link to the question and where users can write their own message. (Twitter provides the interface.)

In my case, however, when the tweet is sent, rather then there being a link back to the page and some text pulled from it, I’d like to have just an image.

Practice As Follows

Twitter has no official way of sharing image. You have to use Twitter card. This is my one webpage with nice image. Test that URL on Twitter card validator, you’ll get quite image. That is like your example with Bloomberg’s twitter status link. Now you can click this link to tweet which is of my that webpage (of course you can delete that tweet, it is example for testing). You’ll get big image with option to customize text. Those are among what you wanted.

Above Twitter share hyperlink’s parameters

The hyperlink I gave you is like :

https://twitter.com/intent/tweet?text=Cheapest%20CDNs%20With%20HTTPS%2C%20IPv6%2C%20HTTP%2F2%2C%20Brotli&url=https%3A%2F%2Fthecustomizewindows.com%2F2017%2F06%2Fcheapest-cdns-https-ipv6-http2-brotli%2F&hastag=AbhishekGhosh&via=AbhishekCTRL&original_referer=https%3A%2F%2Fthecustomizewindows.com%2F2017%2F06%2Fcheapest-cdns-https-ipv6-http2-brotli%2F

https://twitter.com/intent/tweet is constant part. ?text= is what text you want. &url= is URL you’ll share. &via= is optional associated account to mention. &original_referer= is same as &url= in most cases, &hashtags is hostages you want. &hashtags does not work.

But you want it for an image not webpage. That is tricky.

What you need

What you want needs web software with PHP-MySQL like pair. Application will write a unique URL overtime user finish the work with HTML markup for Twitter card for the user generated webpage with image. Twitter card is matter of how the webpage has markups, images, what domain’s webmaster setup etc. You can set that preferred image via webpage’s HTML markup using PHP like language.

Example of prototype application

As example of such thought to develop with WordPress, when I have not published the article, I had the image, but URL to preview was private. It is possible in WordPress to make an unpublished article’s public. That is possible to test with 4 WordPress Plugins as basic example :

  1. https://wordpress.org/plugins/public-post-preview/ (to make unpublished post have a public preview)
  2. https://wordpress.org/plugins/developer-share-buttons/ (to generate twitter share link)
  3. https://wordpress.org/plugins/twitter-cards-meta/ (to generate twitter meta tags)
  4. https://wordpress.org/plugins/live-composer-page-builder/ (to give an way for signed up user to edit on WordPress frontend)

Of course there are newer WordPress API for doing it from on other server.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.