How to embed a tweet from URL using jquery/json/oembed

I'm probably making this a lot hard than it should be, but I'm having a really difficult time finding a way to embed a tweet (https://dev.twitter.com/docs/embedded-tweets) into a webpage dynamically. Ideally, I'd like to have a user enter a twitter status URL (like https://twitter.com/robdelaney/status/329651129988288514), click a button, and have the tweet embed in a div.

Here's what I've got so far:

$(document).ready(function(){
$("#resolve").click(function(){
    var url = $("#retweet_form_url").val();
    if (url==""){
        $(".controls").addClass("error");
    }
    else {
        $("#tweet_div").show();
        $.ajax({
            url: "https://api.twitter.com/1/statuses/oembed.json?url="+url,
            dataType: "jsonp",
            success: function(data){
                // Derp! What do I do here? 
            }
        });
    }
})
})

When I test this with a URL I do get a JSON response back from twitter than includes the entire HTML needed to embed the tweet, but when I try to parse it I can't get anything to appear in my div. Can anyone point me in the right direction?

Thanks in advance to any help you can offer!

Answers


data is an object containing the tweet details, including an html member containing the actual embed code. So:

// ...
   success: function(data){
            $("#tweet_div").html(data.html);
        }
// ...

Need Your Help

Android - Custom dynamically-generated compound View recreated in RecyclerView, causing poor performance

android performance android-layout android-view android-recyclerview

I'm using a custom CompoundView which extends LinearLayout to display items of a RecyclerView. Each item displays an article which contains multiple paragraphs and images. The CompoundView adds Tex...

How do I display an image with ltk?

lisp tcl tk sbcl ltk

I have written code to read a windows bitmap and would now like to display it with ltk. How can I construct an appropriate object? Is there such functionality in ltk? If not how can I do it directly

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.