从access_token检索user_location返回空字符串

时间:2015-08-14 06:31:50

标签: c# asp.net facebook facebook-graph-api

我已成功为我的网站生成access_token。我能够检索所有必需的信息,除了user_location之外的其他信息。我尝试使用以下两种方法来检索位置,但都返回空字符串。

方式-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();

方式-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;
            }

当我尝试在developer.facebook.com的Graph API Explorer中进行调试时,实际上会收到位置!当我输入参数 location 时,会按预期收到位置。

或者我也尝试用以下方法更改请求网址:

WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/location", faceBookId));

为什么会这样?

1 个答案:

答案 0 :(得分:1)

Facebook的Graph API中没有/user-ID/user_location优势。

/user-ID对象上有location field

user_location是您需要获取的OAuth权限范围的名称,以便能够读取该字段。另见:FB docs