获取Facebook用户名

时间:2011-09-21 11:01:40

标签: c# facebook

我需要获取人们的用户名访问我的页面...我正在关注以下结构: https://developers.facebook.com/docs/authentication/signed_request/

我写了以下代码:

string _authorizationUrl = string.Format("https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}", FB_APPID, Server.UrlEncode(FB_CANVAS_PAGE));
string _signedRequest = Request["signed_request"] as string;

string[] _valuesInRequest = _signedRequest.Split(new char[] {'.'}, 2);

string _stringToDecode = _valuesInRequest[1].Replace("-_","+/");

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
System.Text.Decoder decoder = encoding.GetDecoder();

byte[] _byteToDecode = Convert.FromBase64String(_stringToDecode);
int charCount = decoder.GetCharCount(_byteToDecode, 0, _byteToDecode.Length);    
char[] _decodedChar = new char[charCount];
decoder.GetChars(_byteToDecode, 0, _byteToDecode.Length, _decodedChar, 0);                   
string result = new String(_decodedChar);

我已登录Facebook并获得此结果:

{"algorithm":"HMAC-SHA256","issued_at":1316602539,"page":{"id":"XXXXXX","liked":false,"admin":false},"user":{"country":"it","locale":"it_IT","age":{"min":21}}}

没有关于用户名的信息。为什么?任何人都可以帮助我吗?

谢谢

1 个答案:

答案 0 :(得分:1)

由于隐私问题,此信息不会,也可能永远不会提供。获取有关谁正在访问您的Facebook页面的识别信息的唯一方法是让用户对您的应用程序进行身份验证并让他们批准它。然后你可以在/我调用图形api来获取他们的id和名字。