在 twitter api 1.1 中格式化推文 [英] Format Tweets in twitter api 1.1

查看:26
本文介绍了在 twitter api 1.1 中格式化推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试升级我客户的帐户以使用新的 Twitter API 1.1.我做了很多研究,并在此处列出的 Stack Overflow 上找到了一些代码:https://github.com/J7mbo/twitter-api-php.

I am trying to upgrade my client's account to use the new Twitter API 1.1. I've done a lot of research, and found some code here on Stack Overflow that is listed here: https://github.com/J7mbo/twitter-api-php.

所以,我已经让代码工作(大部分),但我没有列出推文,而是得到一个代码列表:

So, I've got the code working (for the most part) but instead of listing tweets, I get a list of code:

[{"created_at":"Wed Jun 12 13:06:28 +0000 2013","id":344802886762512386,"id_str":"344802886762512386","text":"Loading a #prefabarch for delivery the fun way #archkit #framing #razor https:\/\/t.co\/oh2WfbCPNi","source":"\u003ca href=\"http:\/\/vine.co\" rel=\"nofollow\"\u003eVine - Make a Scene\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":47689193,"id_str":"47689193","name":"Archways & Ceilings","screen_name":"Archking57","location":"Arlington, TX","description":"We supply framing kits for Dome Ceilings, Groin Vaults, Barrel Vaults, Coves, and Archways","url":"http:\/\/t.co\/FssCqf6lGz","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/FssCqf6lGz","expanded_url":"http:\/\/www.archwaysandceilings.com","display_url":"archwaysandceilings.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":351,"friends_count":88,"listed_count":10,"created_at":"Tue Jun 16 17:48:23 +0000 2009","favourites_count":0,"utc_offset":-21600,"time_zone":"Central Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":331,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000505","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/223605213\/ACME-YOUTUBE-LOW-QUALITY.jpg","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/223605213\/ACME-YOUTUBE-LOW-QUALITY.jpg","profile_background_tile":true,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1927262664\/ACME_Logo_normal.jpg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1927262664\/ACME_Logo_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/47689193\/1362599335","profile_link_color":"560AFA","profile_sidebar_border_color":"850D2B","profile_sidebar_fill_color":"020501","profile_text_color":"CF0830","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":false,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"prefabarch","indices":[10,21]},{"text":"archkit","indices":[47,55]},{"text":"framing","indices":[56,64]},{"text":"razor","indices":[65,71]}],"symbols":[],"urls":[{"url":"https:\/\/t.co\/oh2WfbCPNi","expanded_url":"https:\/\/vine.co\/v\/blvep6iJVzp","display_url":"vine.co\/v\/blvep6iJVzp","indices":[72,95]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Wed Jun 12 12:15:41 +0000 2013","id":344790103782207489,"id_str":"344790103782207489","text":"Learn how to design, plan and build arched ceilings http:\/\/t.co\/YXr6rVNnjL #vr4smallbiz","source":"\u003ca href=\"http:\/\/www.verticalresponse.com\" rel=\"nofollow\"\u003eVerticalResponse\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":47689193,"id_str":"47689193","name":"Archways & Ceilings","screen_name":"Archking57","location":"Arlington, TX","description":"We supply framing kits for Dome Ceilings, Groin Vaults, Barrel Vaults, Coves, and Archways","url":"http:\/\/t.co\/FssCqf6lGz","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/FssCqf6lGz","expanded_url":"http:\/\/www.archwaysandceilings.com","display_url":"archwaysandceilings.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":351,"friends_count":88,"listed_count":10,"created_at":"Tue Jun 16 17:48:23 +0000 2009","favourites_count":0,"utc_offset":-21600,"time_zone":"Central Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":331,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000505","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/223605213\/ACME-YOUTUBE-LOW-QUALITY.jpg","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/223605213\/ACME-YOUTUBE-LOW-QUALITY.jpg","profile_background_tile":true,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1927262664\/ACME_Logo_normal.jpg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1927262664\/ACME_Logo_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/47689193\/1362599335","profile_link_color":"560AFA","profile_sidebar_border_color":"850D2B","profile_sidebar_fill_color":"020501","profile_text_color":"CF0830","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":false,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"vr4smallbiz","indices":[75,87]}],"symbols":[],"urls":[{"url":"http:\/\/t.co\/YXr6rVNnjL","expanded_url":"http:\/\/p0.vresp.com\/l2fZaa","display_url":"p0.vresp.com\/l2fZaa","indices":[52,74]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]

我不知道我哪里出错了!下面是我的 PHP 代码:

I can't figure out where I went wrong! Below is my PHP code:

require_once('include/twitter-api-php-master/TwitterAPIExchange.php');
$settings = array(
    'oauth_access_token' => "MYKEY",
    'oauth_access_token_secret' => "MYKEY",
    'consumer_key' => "MYKEY",
    'consumer_secret' => "MYKEY"
);
 $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
 $getfield = '?screen_name=archking57&count=2&exclude_replies=true';
 $requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();

所以我的问题是为什么它不只显示推文?如何将其格式化为推文?

So my question is why isn't it showing just the tweets? How can I format it into tweets?

推荐答案

所以你得到的是 json,这是标准的 Twitter API 响应格式.

So what you're getting back is json, which is the standard twitter API response format.

使用 PHP 的 json_decode():

$result = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
var_dump(json_decode($result));`

您会得到如下所示的内容:

You'll get something that looks like this:

这看起来更像您想要的数据吗?

Does that look more like the data you're after?

这篇关于在 twitter api 1.1 中格式化推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆