格式Tweet在twitter api 1.1中

时间:2013-06-13 15:34:41

标签: php twitter

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

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

[{"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代码:

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

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

1 个答案:

答案 0 :(得分:0)

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

使用PHP的 json_decode()

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

你会得到这样的东西:

enter image description here

这看起来更像是你追求的数据吗?