How to get image url from tweets using the Twitter API -


i'm using code:

require_once ("twitteroauth.php");  define('consumer_key', 'xxx'); define('consumer_secret', 'xxx'); define('access_token', 'xxx'); define('access_token_secret', 'xxx');  $toa = new twitteroauth(consumer_key, consumer_secret, access_token, access_token_secret);  $query = array(   "q" => "#misiones",   "result_type" => "recent",   "include_entities" => "true" );  results = $toa->get('search/tweets', $query);  foreach ($results->statuses $result) {    $user = $result->user->screen_name;   $text = $result->text; 

to tweets whit hashtag #misiones(the name of place i'm live). works fine i'm trying image url (if tweet have some).
tryed $result->media , $result->media->media_url , other convinations without succcess.

tweet entities looking access pictures. entities provide structured data tweets including expanded urls , media urls. located under entities attribute in tweet objects both twitter rest , streaming apis.

as result, answer question, if tweet contains 1 picture, url located here:

$media_url = $result->entities->media[0]->media_url; 

below php snippet can add existing foreach loop, bit more elaborate handle whether or not tweet contains media urls:

if (isset($result->entities->media)) {     foreach ($result->entities->media $media) {         $media_url = $media->media_url; // or $media->media_url_https ssl version.     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -