Facebook connect - api_client->users_getInfo throws error Cannot use string offset as an array

Posted by Gublooo on Stack Overflow See other posts from Stack Overflow or by Gublooo
Published on 2010-04-23T21:11:09Z Indexed on 2010/04/23 21:13 UTC
Read the original article Hit count: 1065

Hey guys

I have this piece of code which works 90% of the time:

$user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','proxied_email'));
$firstName=$user_details[0]['first_name'];

But sometimes I get this error:

Fatal error: Cannot use string offset as an array for line
$firstName=$user_details[0]['first_name'];

I have read several people report the same issue - but I'm still not clear as to what is the reason - Am I getting this error because facebook is not returning any results or am I getting because it is returning only a single array instead of array of arrays.

This is the fix I'm thinking of:

if (!is_array($user_details)) {
$firstName='';
}
else
{
$firstName = ($user_details[0]) ? $user_details[0]['first_name'] : $user_details['first_name'];
}

Also if I'm not getting the name - is it because of a timeout issue or something else?

Thanks

© Stack Overflow or respective owner

Related posts about facebook

Related posts about facebook-connect