我编写了一个 CodeIgniter 应用程序,该应用程序输入 Twitter 屏幕名称,然后从 Twitter API 1.1 获取有关此用户的数据。如果 Twitter 屏幕名称不存在,则返回以下错误:
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Sorry, that page does not exist [code] => 34 ) ) )
我的问题是,如何在我的函数中验证/检查上述错误get_user_data(...)
?34
如果页面/用户不存在,我想返回,以便我可以显示适当的未找到错误视图。任何帮助将不胜感激。提前致谢!
// ...
$this->form_validation->set_rules('username', 'username', 'required');
$username = $this->input->post('username');
if($this->form_validation->run() === FALSE || $this->val_username($username) === FALSE)
{
$data = 'Validation Problems';
$this->view('search_page2',$data);
}
else
{
$twitter = new TwitterAPIExchange($settings);
$friends_list_url = 'https://api.twitter.com/1.1/users/show.json';
$friends_list = json_decode($this->get_user_data($username, $twitter, $friends_list_url));
}
}
}
private function get_user_data($username, $twitter, $url)
{
$getfield = '?screen_name=' . $username;
$request_method = 'GET';
return $twitter->setGetfield($getfield)
->buildOauth($url, $request_method)
->performRequest();
}
// ...