我已经得到了我所有的tweet feed显示…但它完全没有格式。谁能告诉我最后收尾的正确方向?我已经创建了一个tweet模型,结果打印在控制器中。但目前它正在打印json文件中的所有内容。下面是我的模型代码…
<?php
类Tweet_model扩展CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_tweet()
{
// Load the rest client spark
$this->load->spark('restclient/2.1.0');
// Load the library
$this->load->library('rest');
// Run some setup
$this->rest->initialize(array('server' => 'http://api.twitter.com/'));
// Pull in an array of tweets
$tweets = $this->rest->get('1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=jenksuy&count=2');
return $tweets;
}
}
和下面是我的控制器代码…
$myTweets = $this->tweet_model->get_tweet();
print_r($myTweets);
,但它显示了json文件中的每一个信息,就像下面的链接…
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jenksuy&数= 2
我怎么能解决这个问题,只是显示格式化的推文?
首先,这样解析json数据
$tweetobjects = json_decode($tweets)
现在,如果您想显示每条消息,您必须这样做:
foreach ($tweetobjects['results'] as $tweet) {
echo $tweet['text'];
}