views:

192

answers:

2

I'm writing a Facebook iframe/Facebook Connect application with PHP client library and in one of the pages, I need to retrieve the user's current location, either city or country.

I have added "Request for Permission" for all possible data in my index file.

 $user_id = $facebook->require_login($required_permissions = 'user_location,publish_stream,email,read_stream,user_about_me,user_activities,user_birthday,user_hometown,user_interests,user_likes,user_status);

This is the code I am using in my application,

 $userInfo = $facebook->api_client->users_getInfo($user_id, array('current_location'));
var_dump($userInfo);
$location = ($userInfo[0]) ? $userInfo[0]['current_location'] : $userInfo['current_location']; 
echo "UserInfo : ".$location;

The result of var_dump($userInfo) is string(0)"" and echo of $location is empty.

Please someone help me.

+1  A: 

That's because you made an error when copying the example. You have the method signature wrong.

// Your version
$facebook->api_client->users_getInfo($user_id,'last_name','first_name');

// From the example
$facebook->api_client->users_getInfo($uid, 'last_name, first_name'); 

See the difference? It's only two parameters - the 2nd is a comma-separated list of field names.

So, since you are not correctly requesting the first_name field from the API, it's not available in the response.

Hence the error when trying to read it.

Peter Bailey
Ok, Now I have changed as you have mentioned. But still I get the same error. `string(0) "" Fatal error: Cannot use string offset as an array in C:\xampplite\htdocs\FacebookQantas\deals.php on line 67` where line number 67 is `$data['last_name'] = $user_details[0]['last_name'];` Please help me
Angeline Aarthi
Does your application have permission to read this data for the given uid?
Peter Bailey
I am trying to read my details only, trying to display my name and location details. So I thought no permissions needed.How to get permissions for my appln to read such data?
Angeline Aarthi
I tried to check if I have permission, by useing the following code snippets:`$permission = $facebook->api_client->call_method('Users.hasAppPermission',array('uid'=>$user_id));` and `$result = $facebook->api_client->users_hasAppPermission('name',$user_id);`Again no answer is displayed in both the cases. Not even a zero.
Angeline Aarthi
Now I have added "Request for Permission" for the appln: `$user_id = $facebook->require_login($required_permissions='user_location,publish_stream,email,read_stream,user_about_me,user_activities,user_events,user_groups, user_hometown,user_interests,user_likes,user_status,friends_events,friends_groups');` and used the code `$userInfo = $facebook->api_client->users_getInfo($user_id, array('current_location'));$location = ($userInfo[0]) ? $userInfo[0]['current_location'] : $userInfo['current_location'];echo $location; ` to get the location,but still no positive results :-( No errors no answer
Angeline Aarthi
You should move all of this into your question or just open a new one.
Peter Bailey
A: 

I'm getting same error since yesterday, no info retrieved from FB, my app was running ok so far... anybody getting same error on every facebook info request?

mike
Please do not add "me too" responses. SO isn't your average forum.
Justian Meyer

related questions