laatste-x-aantal-tweets
Gesponsorde koppelingen
PHP script bestanden
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function get_tweets($username, $count = 10)
{
$url = 'http://twitter.com/statuses/user_timeline/'.urlencode($username).'.json?count='.(int)$count;//Make the url
$ch = curl_init();//Initialise CURL
curl_setopt($ch, CURLOPT_URL, $url);//Set the url
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//We want the data to return
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);//Of course, we don't want your script to run forever, so set a timeout
$json = curl_exec($ch);//Execute and get the page
curl_close($ch);//Close curl connection
$decode = json_decode($json);//Decode the json
$return = array();
foreach($decode as $tweet)
{
$return[] = $tweet -> text;//And the text to an array
}
return $return;//Return the array
}
$tweets = get_tweets('barackobama', 10);//Get last 10 tweets of Barack Obama
//Foreach tweet display it in a new line
foreach($tweets as $tweet)
{
echo $tweet.'<hr />';
}
?>
function get_tweets($username, $count = 10)
{
$url = 'http://twitter.com/statuses/user_timeline/'.urlencode($username).'.json?count='.(int)$count;//Make the url
$ch = curl_init();//Initialise CURL
curl_setopt($ch, CURLOPT_URL, $url);//Set the url
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//We want the data to return
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);//Of course, we don't want your script to run forever, so set a timeout
$json = curl_exec($ch);//Execute and get the page
curl_close($ch);//Close curl connection
$decode = json_decode($json);//Decode the json
$return = array();
foreach($decode as $tweet)
{
$return[] = $tweet -> text;//And the text to an array
}
return $return;//Return the array
}
$tweets = get_tweets('barackobama', 10);//Get last 10 tweets of Barack Obama
//Foreach tweet display it in a new line
foreach($tweets as $tweet)
{
echo $tweet.'<hr />';
}
?>