1
我已經設置了休息庫由Phil鱘連接到Twitter的API - 它的偉大工程然而(見下文)使用Twitter的API休息笨庫
$this->load->spark('restclient/2.1.0');
$this->load->library('rest');
$this->rest->initialize(array('server' => 'http://twitter.com/'));
$username = 'my-username';
// Pull in an array of tweets
$tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');
此代碼的偉大工程 - 但是Twitter的API documentation建議使用稍微不同的方法(見下文) - 我如何使用這個庫下面的新方法?
$this->load->spark('restclient/2.1.0');
$this->load->library('rest');
$this->rest->initialize(array('server' => 'http://api.twitter.com'));
$username = 'my-username';
// Pull in an array of tweets
$tweets = $this->rest->get('/1/statuses/user_timeline.xml?screen_name='.$username);
除非我失去了一些東西:
https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2
不確定這是否是@Zabs問題的一部分,但同樣的方法當然可以通過更改其對user_timeline的請求中的擴展來請求JSON。 – rjz 2012-08-15 15:49:50
返回一個'Not authorized'錯誤,這很奇怪,因爲它看起來非常簡單 - 雖然我可以看到我提供的第一次嘗試返回一個XML文檔,而後者返回json值。 – Zabs 2012-08-15 15:50:11
我只是編輯了代碼中的一個小錯誤。 – simnom 2012-08-15 15:52:28