Reputation: 2706
I have successfully generated access_token
for my website. I am able to retrieve all the required information, except one i.e., user_location
. I tried to use the following two methods to retrieve location , but both return empty string.
Method-1
string access_tokens = tokens["access_token"];
var client = new FacebookClient(access_tokens);
dynamic me = client.Get("me");
string user_location me["user_location"].ToString();
Method-2
string user_location = GetUserLocation(fb_id);
//and here is the method
public static string GetUserLocation(string faceBookId)
{
WebResponse response = null;
string user_location = string.Empty;
try
{
WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/user_location", faceBookId));
response = request.GetResponse();
user_location = response.ResponseUri.ToString();
}
catch (Exception e)
{
//catch exception
}
finally
{
if (response != null) response.Close();
}
return user_location;
}
Location is actually received when I try to debug in the Graph API Explorer at developer.facebook.com ! When I put the parameter location
- the location is received as expected.
Alternately I also tried to change the request URL with this :
WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/location", faceBookId));
Why is this happening ?
Upvotes: 0
Views: 48
Reputation: 2429
There is no /user-ID/user_location
edge in Facebook's Graph API.
There is a location
field on the /user-ID
object.
user_location
is the name of the OAuth permission scope that you need to obtain in order to be able to read that field. See also: FB docs.
Upvotes: 1