Jump to content

Twitter api parsing with php help


mavera2

Recommended Posts

By using twitter api, i'm trying to get latest trends.

I need to take trends name and creation time of the list.

Can you help me to obtain the values from the array?

Thank you

 

This code doesn't work.

<?php

$jsonurl = 'http://api.twitter.com/1/trends/44418.json';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);

foreach ( $json_output->trends as $trend )
{
    echo "{$trend->name}\n";
}


?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/247692-twitter-api-parsing-with-php-help/
Share on other sites

try this:

<?php
$jsonurl = 'http://api.twitter.com/1/trends/44418.json';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json,true);
$trends = $json_output[0]['trends'];
foreach ( $trends as $trend ){
echo $trend['name']."<br />";
}
?>

 

*whenever you're in doubt with arrays, it's best to use:

echo '<pre>';
print_r($array);

to look at the whole structure of the returned/converted array.

 

EDIT: Sorry, forgot the creation date/time, it will be in:

echo $json_output[0]['as_of'];

try this:

<?php
$jsonurl = 'http://api.twitter.com/1/trends/44418.json';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json,true);
$trends = $json_output[0]['trends'];
foreach ( $trends as $trend ){
echo $trend['name']."<br />";
}
?>

 

*whenever you're in doubt with arrays, it's best to use:

echo '<pre>';
print_r($array);

to look at the whole structure of the returned/converted array.

 

EDIT: Sorry, forgot the creation date/time, it will be in:

echo $json_output[0]['as_of'];

 

That really helped me much :))

 

Thank you for your help and suggestions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.