working example of tweet with image using javascript django

帅比萌擦擦* 提交于 2020-01-06 20:24:55

问题


I am trying to tweet with image using javascript.I read about cards, and put the following on page i am sharing:

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="http://203.110.93.244/">
<meta name="twitter:creator" content="@SarahMaslinNir">
<meta name="twitter:title" content="Parade of Fans for Houston’s Funeral">
<meta name="twitter:description" content="NEWARK - The guest list and parade of limousines witproject here.">
<meta name="twitter:image" content="http://www.promon.in/media/images/products/2015/09/listing_image_vsRFOqw.jpg">

then i use this javascript to tweet:

twttr.widgets.createShareButton(
        'http://203.110.93.244/offers/eat-n-drink/Delhi-greater-kailash-rara-avis/81/',
        document.getElementById('twitter-btn'),
        {
            text: '#HelloWorld',
        });

Problem is, I am not getting any image thumbnail. Please guide me towards a viable solution. Thanks.


回答1:


Something as follows works for me. It opens a window whenever the user clicks a button... It sends the "URL" of the source page, "via" which is your twitter username, and "text" which is whatever message you want to appear in there. Note that the amount of text is limited and if too long Twitter silently eliminate part of the data.

The page URL with the image must appear first. You can test the validity of the page here: https://cards-dev.twitter.com/validator

jQuery("#twitter-share-button").click(function(e)
  {
    e.preventDefault();

    var uri = "http://203.110.93.244/offers/eat-n-drink/Delhi-greater-kailash-rara-avis/81/";
    var tweet = "https://twitter.com/intent/tweet?url="
          + encodeURI(uri)
          + "&via=yourtwittername&text="
          + encodeURI(uri)
          + encodeURI(" #your-hash-tag ")
          + encodeURI("some more text here");
    window.open(tweet, "Share on Twitter");
  });


来源:https://stackoverflow.com/questions/34430871/working-example-of-tweet-with-image-using-javascript-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!