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
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'];

Link to comment
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'];

 

That really helped me much :))

 

Thank you for your help and suggestions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.