Search data API Twitter

2

I am consulting data to Twitter as follows:

<?php
$consumerKey    = '';
$consumerSecret = '';
$oAuthToken     = '';
$oAuthSecret    = '';

require_once('twitteroauth.php');

$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);

$result = $tweet->get('search/tweets', array('q' => '#HASHTAG_BUSCADA', 'count' => 1, 'result_type' => 'recent'));

$out="";
$t = json_decode($result, true);
foreach ($t['statuses'] as $user) {
    echo $res = $out."".$user['text']."<br/>";
}
?>

With this I get the "text" of the last tweet published with the "# HASHTAG_BUSCADA" but I would also like to get the "screen_name" . If I do echo $result I can see that that data is there, but I do not know how to show it?

Example:

echo $result :

{
  "statuses": [
    {
      "created_at": "Tue Oct 18 20:18:59 +0000 2016",
      "id": 7.8847448056577e+17,
      "id_str": "788474480565768192",
      "text": "Les comparto un peque\u00f1o flash de lo que fue nuestro show en el #Antelfest - #Elsuperhobby\nNo paramos! https:\/\/t.co\/pnN6sdO2RG",
      "truncated": false,
      "entities": {
        "hashtags": [
          {
            "text": "Antelfest",
            "indices": [
              63,
              73
            ]
          },
          {
            "text": "Elsuperhobby",
            "indices": [
              76,
              89
            ]
          }
        ],
        "symbols": [

        ],
        "user_mentions": [

        ],
        "urls": [
          {
            "url": "https:\/\/t.co\/pnN6sdO2RG",
            "expanded_url": "http:\/\/fb.me\/5jfcTPaOu",
            "display_url": "fb.me\/5jfcTPaOu",
            "indices": [
              102,
              125
            ]
          }
        ]
      },
      "metadata": {
        "iso_language_code": "es",
        "result_type": "recent"
      },
      "source": "<a href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\">Facebook<\/a>",
      "in_reply_to_status_id": null,
      "in_reply_to_status_id_str": null,
      "in_reply_to_user_id": null,
      "in_reply_to_user_id_str": null,
      "in_reply_to_screen_name": null,
      "user": {
        "id": 288743808,
        "id_str": "288743808",
        "name": "Martin Palomeque",
        "screen_name": "MartinPalomeque",
        "location": "Uruguay",
        "description": "M\u00fasico en El Super Hobby",
        "url": "http:\/\/t.co\/MqRJDhC4UU",
        "entities": {
          "url": {
            "urls": [
              {
                "url": "http:\/\/t.co\/MqRJDhC4UU",
                "expanded_url": "http:\/\/www.myspace.com\/martinpalomeque",
                "display_url": "myspace.com\/martinpalomeque",
                "indices": [
                  0,
                  22
                ]
              }
            ]
          },
          "description": {
            "urls": [

            ]
          }
        },
        "protected": false,
        "followers_count": 219,
        "friends_count": 110,
        "listed_count": 0,
        "created_at": "Wed Apr 27 11:47:32 +0000 2011",
        "favourites_count": 32,
        "utc_offset": -7200,
        "time_zone": "Greenland",
        "geo_enabled": false,
        "verified": false,
        "statuses_count": 1562,
        "lang": "es",
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "C0DEED",
        "profile_background_image_url": "http:\/\/pbs.twimg.com\/profile_background_images\/240474891\/fondo_martin_palomeque.jpg",
        "profile_background_image_url_https": "https:\/\/pbs.twimg.com\/profile_background_images\/240474891\/fondo_martin_palomeque.jpg",
        "profile_background_tile": false,
        "profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/619274158694866945\/Pt0bn5Fc_normal.jpg",
        "profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/619274158694866945\/Pt0bn5Fc_normal.jpg",
        "profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/288743808\/1436481438",
        "profile_link_color": "0084B4",
        "profile_sidebar_border_color": "C0DEED",
        "profile_sidebar_fill_color": "DDEEF6",
        "profile_text_color": "333333",
        "profile_use_background_image": true,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "following": false,
        "follow_request_sent": false,
        "notifications": false,
        "translator_type": "none"
      },
      "geo": null,
      "coordinates": null,
      "place": null,
      "contributors": null,
      "is_quote_status": false,
      "retweet_count": 0,
      "favorite_count": 0,
      "favorited": false,
      "retweeted": false,
      "possibly_sensitive": false,
      "lang": "es"
    }
  ],
  "search_metadata": {
    "completed_in": 0.018,
    "max_id": 7.8847448056577e+17,
    "max_id_str": "788474480565768192",
    "next_results": "?max_id=788474480565768191&q=%23antelfest&count=1&include_entities=1&result_type=recent",
    "query": "%23antelfest",
    "refresh_url": "?since_id=788474480565768192&q=%23antelfest&result_type=recent&include_entities=1",
    "count": 1,
    "since_id": 0,
    "since_id_str": "0"
  }
}

echo $res :

Les comparto un pequeño flash de lo que fue nuestro show en el #Antelfest - #Elsuperhobby No paramos! https://t.co/pnN6sdO2RG

But I can not extract the "screen_name" that would be the following:

MartinPalomeque
    
asked by Winston 18.10.2016 в 21:06
source

1 answer

1

I leave the example working in: See Demo

$res = '';

foreach ($t['statuses'] as $user) {
    $res .= $user['text']."\n\n";
    $res .= $user['user']['screen_name'];
}

echo $res
    
answered by 18.10.2016 / 23:27
source