I'm attempting to get and display images posted in a tweet with php via the entities parameter. I have include_entities in my url and can see the entities in the returned json.
In my foreach loop, I am doing the following:
foreach($results as $result){
$media_url = $result->entities->media->media_url;
$media_size_h = $result->entities->media->sizes->small->h;
$media_size_w = $result->entities->media->sizes->small->w;
...
}
However, this is not returning anything.
For my output, I have...
if(strlen($media_url) > 0)
{
//format table for tweets with images
} else {
//format table for regular tweets
}
And this is the json...
array(20) {
[0]=>
object(stdClass)#5 (21) {
...
["entities"]=>
object(stdClass)#7 (4) {
["media"]=>
array(1) {
[0]=>
object(stdClass)#8 (10) {
["type"]=>
string(5) "photo"
["media_url"]=>
string(38) "http://photourl.jpg"
...
["sizes"]=>
object(stdClass)#9 (4) {
["thumb"]=>
object(stdClass)#10 (3) {
["resize"]=>
string(4) "crop"
["h"]=>
int(150)
["w"]=>
int(150)
}
...
}
Any ideas why this is not working? Any help would be much appreciated!
$result->entities->media->
this is an array as seen in structure... try using
$media_url = $result->entities->media[0]->media_url;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With