使用twitter api来发推html元素的内容

时间:2017-02-22 02:00:06

标签: javascript html

我正在尝试创建一个随机引用生成器,然后使用推文按钮来发布当前引用(

元素的内容),但我只能通过Twitter api来发布推文,我有研究和阅读但完全卡住任何帮助将是美好的! 这是带有twitter按钮的HTML

<body>
<h1>J.R.R. Tolkien Quote Machine!</h1>

<div id ="stuff">
<img id="image" src="http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zpsukywovht.jpg">
<h2 id = "quotetext">Press the button to discover the first quote.</h2>

<button id = "quotebutton" onclick = "randomQuote()">Get a new quote...      </button>

</div>
<!--tweet the url-->
<a href="https://twitter.com/share" class="twitter-share-button" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


</body>

这是我的javascript ...

var myQuotes = [
  "'Faithless is he that says farewell when the road darkens.'",
  "'All we have to decide is what to do with the time that is given us.'",
  "'If more of us valued food and cheer and song above hoarded gold, it would be a merrier world.'",
  "'Never laugh at live dragons.'",
  "'There is some good in this world, and it's worth fighting for.'",
  "'Faithless is he that says farewell when the road darkens.'",
  "'The world is indeed full of peril, and in it there are many dark places; but still there is much that is fair, and though in all lands love is now mingled with grief, it grows perhaps the greater.'",
  "'Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement.'",
  "'Not all those who wander are lost.'",
  "'I will not say: do not weep; for not all tears are an evil.'",
  "'Little by little, one travels far'",
  "'Courage is found in unlikely places.'",
  "'It's the job that's never started as takes longest to finish.'",
  "'There is nothing like looking, if you want to find something. You certainly usually find something, if you look, but it is not always quite the something you were after.'",
  "'The wide world is all about you: you can fence yourselves in, but you cannot forever fence it out.'",
  "'It may be the part of a friend to rebuke a friend's folly.'",
]
var myImages = [
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/p0232nkj_zpsevgnb5vx.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/lord-of-the-rings-quiz-orig_zpsse5k5mrg.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/12d212546fbb50f1f278db8d3c893b05_zpsqzlpz91p.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgres1_zpsdsmi4elj.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/samwise-gamgee_zpsrhuv2u33.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/p0232nkj_zpsevgnb5vx.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images2_zpsgyxpexod.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/gollum_zpsy583lrzv.png",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zpsonmjtyty.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imagesq_zpsfgguq2ha.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgres_zpsesxdolbh.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/images_zps9qwoibjr.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/imgresw_zpseizew5r4.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/The-Hobbit-An-Unexpected-Journey-2012-1_zpsjxz1lw9i.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/middleearthlargelargerstill_zpscp5xil1m.jpg",
  "http://i1376.photobucket.com/albums/ah30/joecarlowittosi/lord_of_the_rings-_the_fellowship_of_the_ring_wallpaper_15_1024_zpssafzudw9.jpg"
]

function randomQuote() {
  var randomNumber = Math.floor(Math.random() * (myQuotes.length));
  document.getElementById("quotetext").innerHTML = myQuotes[randomNumber];
  document.getElementById("image").src = myImages[randomNumber];
}

0 个答案:

没有答案