douyanzan9145 2014-03-16 20:54
浏览 58
已采纳

使用Twitter json feed中的display_url

I'm running into an issue that I'm hoping is reasonably straight forward as far as a solution. I'm using Thomas Yung's Twitter JSON to RSS https://github.com/thomasyung/twitter-json-to-rss and I've run into an issue with trying to get the script to actually output the display_url variable. I'm not a PHP wiz by any stretch, but it seems reasonably simple how they are accessing the various information points in twitter_json_to_rss.php starting at line 85.

$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);

Now it seems reasonably straightforward how the variables are being called based on the structure of the json output I included below. If I want to output the display_url should be as simple as calling $line->entities->urls->display_url but that just doesn't seem to be working. Is there something I'm missing here? It seems I can't access anything from the entities section, but I can pull in the majority of the other variables available in the JSON. Is there some things I'm not allowed to access from the Twitter API or something like that? I'm just at a loss as to why it's not working.

 {
  "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条回答 默认 最新

  • douxing6532 2014-03-16 20:59
    关注

    Your urls seems to be an array. Try this -

    $line->entities->urls[0]->display_url
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里