I am currently using the Twitter API v1.1.
I am displaying the latest 5 tweets of a particular user. The API responds with a data object that contains an entities object which then contains an array of urls, that looks like the following.
display_url:"youtube.com/watch?v=WtM3wP…"
expanded_url:"https://www.youtube.com/watch?v=WtM3wPVhkik"
url:"https://www.youtube.com/watch?v=WtM3wPVhkik"
I want to display the tweets in a timeline with a thumbnail, or else an option to play the video from the page. Can anyone suggest a way of doing this. I couldn't find anything on SO, or through Google suggesting a solution.
The relevant twitter documentation can be found here.
See my code below if it helps:
get_tweets.php
<?php
require_once('twitter_proxy.php');
// Twitter OAuth Config options
$oauth_access_token = '********';
$oauth_access_token_secret = '********';
$consumer_key = '********';
$consumer_secret = '********';
$user_id = '********';
$screen_name = 'StackOverflow';
$count = 5;
$twitter_url = 'statuses/user_timeline.json';
$twitter_url .= '?user_id=' . $user_id;
$twitter_url .= '&screen_name=' . $screen_name;
$twitter_url .= '&count=' . $count;
// Create a Twitter Proxy object from our twitter_proxy.php class
$twitter_proxy = new TwitterProxy(
$oauth_access_token, // 'Access token' on https://apps.twitter.com
$oauth_access_token_secret, // 'Access token secret' on https://apps.twitter.com
$consumer_key, // 'API key' on https://apps.twitter.com
$consumer_secret, // 'API secret' on https://apps.twitter.com
$user_id, // User id (http://gettwitterid.com/)
$screen_name, // Twitter handle
$count // The number of tweets to pull out
);
// Invoke the get method to retrieve results via a cURL request
$tweets = $twitter_proxy->get($twitter_url);
echo $tweets;
?>
tweets.js
$(function(){
$.ajax({
url: 'get_tweets.php',
type: 'GET',
success: function(response) {
console.log(response)
if (typeof response.errors === 'undefined' || response.errors.length < 1) {
var $tweets = $('<ul></ul>');
$.each(response, function(i, obj) {
$tweets.append('<li>' + obj.text + '</li>');
});
$('.tweets-container').html($tweets);
} else {
$('.tweets-container p:first').text('Response error');
}
},
error: function(errors) {
$('.tweets-container p:first').text('Request error');
}
});
});
Please see below for one of the objects returned