I am getting the following undefined index
error when I try to access the screen_name
key value pair from Twitter API 1.1 User Timeline https://api.twitter.com/1.1/statuses/user_timeline.json
A PHP Error was encountered
Severity: Notice
Message: Undefined index: screen_name
Filename: controllers/search.php
Line Number: 98
I can see the screen_name key when I print_r(); the associative array that stores the results:
Array ( [0] => Array ( [created_at] => Tue Mar 19 21:55:31 +0000 2013 [id] => 3.141330578148E+17 [id_str] => 314133057814798336 [text] => Win a 4-Pack of tickets to the @VanAutoShow March 26-31 via @604Now – http://t.co/2G0pyNNgLl RT to Enter! [source] => Twitter for Mac [truncated] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => Array ( [id] => 128700677 [id_str] => 128700677 [name] => Bernard Poon [screen_name] => StackOverflow [location] => Vancouver, BC [description] => Code Monkey that calls Vancouver home. Loves Apple products and newbie photographer. [url] => http://t.co/wlxhr5tpes [entities] => Array ( [url] => Array ( [urls] => Array ( [0] => Array ( [url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [indices] => Array ( [0] => 0 1 => 22 ) ) ) ) [description] => Array ( [urls] => Array ( ) ) ) [protected] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => Thu Apr 01 23:16:57 +0000 2010 [favourites_count] => 0 [utc_offset] =>
I am able to access the screen_name key value pair if I use the Users Show TWitter API 1.1 resource with no errors. However, when I use the User Timeline Twitter API 1.1 resource, I get the above undefined index
error. Below is a code snippet of the function I'm using to access both of these resources with different results:
function does_user_exist($r)
{
// convert to associative array
// inorder to search for keys
$a = json_decode($r, true);
echo "Screen Name: " . $a['screen_name'];
}
Any assistance will be greatly appreciated. Thanks in advance.