使用c#中的身份验证令牌获取用户详细信息

时间:2015-07-13 09:28:23

标签: javascript c# facebook authentication servicestack

我正在使用servicestack,在客户端,我正在进行facebook身份验证,这将提供一个登录的登录帖子

 function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!';
    });
  }

完成身份验证后,将设置cookie值fbsr_Appid,其中包含身份验证令牌

当用户向servicestack发出请求时,我将能够从上下文中的cookie值获取此身份验证令牌。 现在,如何使用此令牌获取用户的用户ID /电子邮件ID?

目前,我可以使用以下网址

获取访问令牌的到期时间
https://graph.facebook.com/oauth/access_token_info?client_id=APPID&access_token=xxxxxxxxx

以下面的格式返回响应

{
access_token: "xxxxxxxx",
token_type: "bearer",
expires_in: 5560
}

1 个答案:

答案 0 :(得分:1)

最后我找到了一种方法

var details = string.Format("https://graph.facebook.com/me?access_token={0}", token);

这是以下面的格式给出回应

{
id: "344657773358323",
email: "zz@gmail.com",
first_name: "xxxxxx",
gender: "male",
last_name: "xxxxxx",
link: "https://www.facebook.com/app_scoped_user_id/xxxxx/",
locale: "en_US",
name: "xxxx  xxxx",
timezone: 5.5,
updated_time: "xx-xx-xx:07:xx+0000",
verified: true
}