Unable to get expanded_url


Hi there!

I’m trying to get expanded_urls from a search action but I’m unable to get it. The urls stay empty… My code is:

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?f=realtime&q=decorrespondent.nl%2F&src=typd';
$twitter = new TwitterAPIExchange($settings);    
$api_response = $twitter ->setGetfield($getfield)
                     ->buildOauth($url, $requestMethod)

$response = json_decode($api_response);

foreach($response->statuses as $tweet)
  echo "{$tweet->user->screen_name} : {$tweet->entities->urls->expanded_url}\n <br />";

hope that someone can help me!


I noticed the array is a weird one:

[urls] => Array
[0] => Array
[url] => https://t.co/y0co8M9Uhs
[expanded_url] => https://decorrespondent.nl/2262/Dit-moet-je-weten-over-de-decentralisaties-die-deze-week-van-start-gaan/137708160018-a56b

Anyone knows an answer?


Not sure, but would {$tweet->entities->urls[0]->expanded_url} get the value you want?


yeah that works! Thank you so much! :slight_smile:

closed #5