lisovaccaro
lisovaccaro

Reputation: 33956

How do apps get attached images to tweets when using twitter api?

I want to display images attached to tweets next to each tweet if available (I think all links go something like pic.twitter.com). I can think only of one example when this is done which is on Flipboard but I'm sure it's a common practice, however I couldn't find info in twitter documentation on how to do it. Does somebody know how this can be done?

This is how I commonly retrieve tweets in my app:

function searchTwitter(query) {
    alert(jQuery.param(query));
    $.ajax({
        url: 'http://search.twitter.com/search.json?q=pizza',
        dataType: 'jsonp',
        success: function(data) {
            var tweets = $('#tweets');
            tweets.html('');
            for (res in data['results']) {
                tweets.append('<div class="tweet"><p>' + data['results'][res]['text'] + '</p> <div class="accountName"> by ' + data['results'][res]['from_user'] + '</div></div>');
            }
        }
    });
}

Upvotes: 0

Views: 3741

Answers (1)

hvgotcodes
hvgotcodes

Reputation: 120198

Look at the documentation here.

Specifically the part about Media Entities, there are various urls there.

all you need to do is get that url, and put it in an <img> tag, and the browser should fetch it for you.

Alternatively, depending on the rest of your code, you could set the background-image css property to the url.

Upvotes: 3

Related Questions