在网页的JSON结果中只返回Twitter Tweet文本



我有一个网页,希望在其中返回特定用户的最新推文"文本"。

我在这里学习了这个教程-http://www.webdevdoor.com/php/authenticating-twitter-feed-timeline-oauth/

设置一个Twitter应用程序等和相关代码,以返回最新推文的JSON结果。我遇到的问题是返回的JSON信息数组。我已经检查了https://dev.twitter.com/docs/api/1/get/statuses/user_timeline网站如何限制这一点,但似乎找不到它。

以下是返回的示例结果:

> [{"created_at":"Thu Mar 06 02:45:46 +0000
> 2014","id":441404238522875904,"id_str":"441404238522875904","text":"RT
> @womeng: Our own @janetvh shares the story of #womeng + how we choose
> and measure our efforts.
> https://t.co/sEXmIwwPAK","source":"TweetDeck</a>","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":783214,"id_str":"783214","name":"Twitter","screen_name":"twitter","location":"San
> Francisco, CA","description":"Your official source for news, updates
> and tips from Twitter,
> Inc.","url":"http://t.co/5iRhy7wTgu","entities":{"url":{"urls":[{"url":"http://t.co/5iRhy7wTgu","expanded_url":"http://blog.twitter.com/","display_url":"blog.twitter.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":29229772,"friends_count":131,"listed_count":83766,"created_at":"Tue
> Feb 20 14:35:54 +0000
> 2007","favourites_count":26,"utc_offset":-28800,"time_zone":"Pacific
> Time (US &
> Canada)","geo_enabled":true,"verified":true,"statuses_count":1733,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"ACDED6","profile_background_image_url":"http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png","profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png","profile_background_tile":true,"profile_image_url":"http://pbs.twimg.com/profile_images/2284174758/v65oai7fxn47qv9nectx_normal.png","profile_image_url_https":"https://pbs.twimg.com/profile_images/2284174758/v65oai7fxn47qv9nectx_normal.png","profile_banner_url":"https://pbs.twimg.com/profile_banners/783214/1347405327","profile_link_color":"226699","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"F6F6F6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Thu
> Mar 06 02:08:23 +0000
> 2014","id":441394833148481536,"id_str":"441394833148481536","text":"Our
> own @janetvh shares the story of #womeng + how we choose and measure
> our efforts. https://t.co/sEXmIwwPAK","source":"Twitter for
> iPhone</a>","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":437698597,"id_str":"437698597","name":"Twitter
> WomEng","screen_name":"womeng","location":"San Francisco,
> CA","description":"Twitter's Women in Engineering
> Group","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":16019,"friends_count":118,"listed_count":135,"created_at":"Thu Dec 15 18:42:44 +0000
> 2011","favourites_count":26,"utc_offset":-36000,"time_zone":"Hawaii","geo_enabled":true,"verified":true,"statuses_count":290,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/2346587762/6bzyl5e7v13fijy4cs7y_normal.png","profile_image_url_https":"https://pbs.twimg.com/profile_images/2346587762/6bzyl5e7v13fijy4cs7y_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":76,"favorite_count":118,"entities":{"hashtags":[{"text":"womeng","indices":[37,44]}],"symbols":[],"urls":[{"url":"https://t.co/sEXmIwwPAK","expanded_url":"https://www.youtube.com/watch?v=iPo0KLQ4Ihg&index=6&list=PL8k-xHP7bhnKHc5qJeH5YCdfqgJFiYT2N","display_url":"youtube.com/watch?v=iPo0KLu2026","indices":[86,109]}],"user_mentions":[{"screen_name":"janetvh","name":"janet
> van
> huysse","id":74534435,"id_str":"74534435","indices":[8,16]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},"retweet_count":76,"favorite_count":0,"entities":{"hashtags":[{"text":"womeng","indices":[49,56]}],"symbols":[],"urls":[{"url":"https://t.co/sEXmIwwPAK","expanded_url":"https://www.youtube.com/watch?v=iPo0KLQ4Ihg&index=6&list=PL8k-xHP7bhnKHc5qJeH5YCdfqgJFiYT2N","display_url":"youtube.com/watch?v=iPo0KLu2026","indices":[98,121]}],"user_mentions":[{"screen_name":"womeng","name":"Twitter
> WomEng","id":437698597,"id_str":"437698597","indices":[3,10]},{"screen_name":"janetvh","name":"janet
> van
> huysse","id":74534435,"id_str":"74534435","indices":[20,28]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]

由于它的大小,将其作为代码类型,但你会明白的。

理想情况下,我希望推特HTML化,只在页面上显示文本。

假设您已经学习了教程:

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
$last_tweet = $tweets[0]->text;
echo $last_tweet; // win o/

这样做:

json_encode($tweets);

您将数组(包含所有用户的tweet)更改为字符串。。。

最新更新