Reputation: 185
I would like to give users the option to post tweets by entering only the url of the tweet (i.e. they would paste https://twitter.com/inspiredmag/status/342771390283411456 and then the actual tweet embed code, once received will be saved into the database to be displayed later). I'm not too familiar with the twitter api. i assume that once the user enters the url and clicks submit i will be able to get the embed code and then save it. is there a way I can grab it before submit and show a preview to the user?
Upvotes: 4
Views: 1619
Reputation: 185
Figured it out
<script>
$('#tweetLink').on('input', function() {
var url = $('#tweetLink').val();
if(url)
{
$.ajax({
url: "https://api.twitter.com/1/statuses/oembed.json?url="+url,
dataType: "jsonp",
async: false,
success: function(data){
$("#embedCode").val(data.html);
$("#preview").html(data.html)
}
});
}
})
</script>
Upvotes: 5