jeudi 13 août 2015

Retrieving user_location from the access_token returns empty string

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("http://ift.tt/1DOYmIM", 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("http://ift.tt/1HKpRxV", faceBookId));

Why is this happening ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire