8

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.

Randoms
  • 2,110
  • 2
  • 20
  • 31
  • data:.. is in fact not a URL but a [Data URI](https://en.wikipedia.org/wiki/Data_URI_scheme) – Stefan Hegny May 31 '17 at 20:26
  • @StefanHegny Thanks! That helps. Ideas on how I can share that to Facebook? – Randoms May 31 '17 at 20:28
  • Not really, sorry. Hope for some experts to drop in... Do you want to share it to FB or twitter? You seem to intermix these two (now you say facebook, but the question is tagged twitter) – Stefan Hegny May 31 '17 at 20:30
  • @StefanHegny Twitter. Sorry! (Well, both, but Facebook is a slightly different situation I've described in another question.) I'll fix that. – Randoms May 31 '17 at 20:44
  • OK, so I can't edit the bounty text (?), but I meant that I'm looking for a procedure to share **PNG** data (as I've described above) on Twitter, not SVG data, since I've already done the work of changing the format. – Randoms Jun 07 '17 at 17:51
  • The thing you're trying to do requires you to have a Twitter application that users have allowed once. Also making client-side Twitter API requests is discouraged. You should learn how to create a Twitter application and how to authorize the users to send tweets on their behalf. This is the only sane way you must go. Cards or images will be the question then. – Kul-Tigin Jun 10 '17 at 22:36
  • @Kul-Tigin I've registered a Twitter application. If client-side API requests are discouraged, how can I facilitate users' sharing of these images to their Twitter accounts? – Randoms Jun 12 '17 at 18:58

1 Answers1

0

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.

Abhishek Ghosh
  • 1,161
  • 9
  • 19