I wrote a CodeIgniter app that inputs a Twitter screen name, and then fetches data about this user from the Twitter API 1.1. If the Twitter screen name does not exist, it returns the following error:
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Sorry, that page does not exist [code] => 34 ) ) )
My question is, how do I validate/check for the above-mentioned error in my function get_user_data(...)
? I want to return 34
if the page/user does not exist so that I can display an appropriate not found error view. Any assistance will be appreciated. Thanks in advance!
// ...
$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();
}
// ...