【问题标题】:Get user details using the authentication token in c#在 c# 中使用身份验证令牌获取用户详细信息
【发布时间】:2015-07-13 09:28:22
【问题描述】:

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

 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?

目前我可以使用下面的 url 获取访问令牌的到期时间

https://graph.facebook.com/oauth/access_token_info?client_id=APPID&access_token=xxxxxxxxx

返回以下格式的响应

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

【问题讨论】:

    标签: javascript c# facebook authentication servicestack


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 2019-01-27
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      相关资源
      最近更新 更多