使用Twitter json feed中的display_url

时间:2014-03-16 20:54:51

标签: php json twitter rss

我遇到了一个我希望在解决方案方面相当直接的问题。我正在使用Thomas Yung的Twitter JSON到RSS https://github.com/thomasyung/twitter-json-to-rss,我遇到了一个问题,试图让脚本实际输出display_url变量。我不是任何一个PHP wiz,但从第85行开始访问twitter_json_to_rss.php中的各种信息点似乎相当简单。

$title= htmlspecialchars(htmlspecialchars_decode($line->user->name.": ".strip_tags($line->text)));
$description= htmlspecialchars(htmlspecialchars_decode(strip_tags($line->text)));
$url = htmlspecialchars("https://twitter.com/".$line->user->screen_name."/statuses/".$line->id_str);;
$image = (strlen($line->entities->media[0]->media_url)>0) ? htmlspecialchars($line->entities->media[0]->media_url) : null;
$created_at = rfc822Date($line->created_at);

现在,根据下面包含的json输出结构调用变量似乎相当简单。如果我想输出display_url应该像调用$ line-> entities-> urls-> display_url一样简单,但这似乎不起作用。这里有什么我想念的吗?我似乎无法从实体部分访问任何内容,但我可以提取JSON中可用的大多数其他变量。是否有一些我不允许从Twitter API访问的东西或类似的东西?我只是不知道为什么它不起作用。

 {
  "created_at":"Sun Mar 16 19:57:47 +0000 2014",
  "id":445287835055439872,
  "id_str":"445287835055439872",
  "text":"93% of Crimeans vote to join Russia, exit polls show http:\/\/t.co\/57teqvKOmB",
  "source":"\u003ca href=\"http:\/\/www.socialflow.com\" rel=\"nofollow\"\u003eSocialFlow\u003c\/a\u003e",
  "truncated":false,
  "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":972651,
     "id_str":"972651",
     "name":"Mashable",
     "screen_name":"mashable",
     "location":"",
     "description":"News, resources, inspiration and fun for the connected generation. Tweets by @mashable staff.",
     "url":"http:\/\/t.co\/1Gm8aVACKn",
     "entities":{
        "url":{
           "urls":[
              {
                 "url":"http:\/\/t.co\/1Gm8aVACKn",
                 "expanded_url":"http:\/\/mashable.com",
                 "display_url":"mashable.com",
                 "indices":[
                    0,
                    22
                 ]
              }
           ]
        },
        "description":{
           "urls":[

           ]
        }
     },
     "protected":false,
     "followers_count":3870836,
     "friends_count":2740,
     "listed_count":112874,
     "created_at":"Mon Mar 12 01:28:01 +0000 2007",
     "favourites_count":193,
     "utc_offset":-14400,
     "time_zone":"Eastern Time (US & Canada)",
     "geo_enabled":false,
     "verified":true,
     "statuses_count":98940,
     "lang":"en",
     "contributors_enabled":false,
     "is_translator":false,
     "is_translation_enabled":true,
     "profile_background_color":"00AEEF",
     "profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/705312036\/bf7ca2a3f077d7e57b12a5ea4f1db268.png",
     "profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/705312036\/bf7ca2a3f077d7e57b12a5ea4f1db268.png",
     "profile_background_tile":false,
     "profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/3690637553\/5c348fee8afbcefa1978004a864a51ce_normal.png",
     "profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/3690637553\/5c348fee8afbcefa1978004a864a51ce_normal.png",
     "profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/972651\/1369156394",
     "profile_link_color":"00AEEF",
     "profile_sidebar_border_color":"FFFFFF",
     "profile_sidebar_fill_color":"88DBF4",
     "profile_text_color":"3B3B3B",
     "profile_use_background_image":false,
     "default_profile":false,
     "default_profile_image":false,
     "following":false,
     "follow_request_sent":false,
     "notifications":false
  },
  "geo":null,
  "coordinates":null,
  "place":null,
  "contributors":null,
  "retweet_count":74,
  "favorite_count":20,
  "entities":{
     "hashtags":[

     ],
     "symbols":[

     ],
     "urls":[
        {
           "url":"http:\/\/t.co\/57teqvKOmB",
           "expanded_url":"http:\/\/on.mash.to\/1gwwY3W",
           "display_url":"on.mash.to\/1gwwY3W",
           "indices":[
              53,
              75
           ]
        }
     ],
     "user_mentions":[

     ]
  },
  "favorited":false,
  "retweeted":false,
  "possibly_sensitive":false,
  "lang":"en"

},

1 个答案:

答案 0 :(得分:1)

您的urls似乎是一个数组。试试这个 -

$line->entities->urls[0]->display_url