Tweet with image using JavaScript


#1

I’m integration my web application with twitter so that use can tweet an image with the tweet. I’m following https://dev.twitter.com/web/tweet-button/javascript-create to create through javascript.
But there is now way to attach image url with the tweet.

Could you advise how to attach image url with the twee?

Thanks
Maqsood


#2

The web intents and web Tweet composer do not support directly uploading an image with the Tweet. You are free to use the text parameter to specify some text to pre-populate the Tweet composer with, which could be a link to an image or web page with a card, but if you want to upload an image directly, you will need to build your own app which performs media upload.


#3

Hi Andy

Thanks for you reply.
When I use image link in twitter composer it doesn’t show the image preview in the tweet but just text of the link as you can see below.

Is there a way a preview of the image link can be shown in tweet through composer?

I have also tried LinqToTwitter library in C# to upload media which works fine but for that I have to specify ConsumerKey, ConsumerSecret, OAuthToken, OAuthTokenSecret which is for a specific user account all the time. Also through this option there is no user interface from twitter so that user can see the composer screen etc. I want to give option to the user to tweet image in his/her account through my web application and ideally if twitter can handle login flow will be great like how facebook does in the below link https://developers.facebook.com/docs/sharing/reference/feed-dialog

Is there a way in twitter?

Thanks
Maqsood


#4

No there is no way to do this using Twitter web intents, you would have to build that app and have users authenticate to Twitter individually.


#5

How can I authenticate a user using twitter login screens?


#6

How can a preview of the image link of a tweet can be seen in that tweet?


#7

You would sign up for a Twitter application at apps.twitter.com and configure for read-write access.

A visitor to your webpage could enter a Log in with Twitter authorization flow.
https://dev.twitter.com/web/sign-in

If the visitor grants access to your Twitter app to post to a Twitter account on their behalf you can create a new Tweet including media using the Twitter API.
https://dev.twitter.com/rest/reference/post/statuses/update


#8

Thanks for your reply
I have found a simple & easy way through javascript (https://dev.twitter.com/web/tweet-button/javascript-create) to add the url with tweet which will show the image preview in the tweet as below

Now one last thing I would like to select only the text but not the url in tweet screen as below

How can I achieve this?

Thanks
Maqsood


#9

A link preview for the shared URL may be provided via Twitter Cards markup
https://dev.twitter.com/cards/overview