我正在尝试从我的个人资料中获取自己的家乡信息,但它总是返回null。但是,当我为我的帐户获取图形API(https://graph.facebook.com/me/?access_token=)时,它会返回。
这是我的代码:
SocialMatchUser model = new SocialMatchUser();
var authClient = new FacebookOAuthClient(FacebookApplication.Current)
{
AppId = appId,
AppSecret = appSecret,
RedirectUri = new Uri(redirectUrl)
};
dynamic token = authClient.ExchangeCodeForAccessToken(Request.QueryString["code"]);
var client = new FacebookClient(token.access_token);
dynamic me = client.Get("me");
model.ID = Convert.ToInt64(me.id);
model.FullName = me.name;
model.FirstName = me.first_name;
model.LastName = me.last_name;
model.Link = me.link;
model.UserName = me.username;
model.Gender = me.gender;
model.Locale = me.locale;
model.Birthday = me.birthday;
if (me.hometown!= null)
{
model.HometownId = Convert.ToInt64(me.hometown.id);
model.Hometown = me.hometown.name;
}
return View(model);
我在请求或原始身份验证呼叫中遗漏了某些内容以允许访问此额外用户信息吗?
谢谢! -Jason
答案 0 :(得分:2)
您需要请求扩展权限才能读出家乡。
您可以在此处找到详细信息: http://developers.facebook.com/docs/authentication/permissions/