如何从cookie中使用facebook令牌?

时间:2017-01-19 15:03:09

标签: facebook facebook-graph-api cookies

我可以使用方法 FB.getLoginStatus()

在asp.net mvc应用程序的客户端获取facebook访问令牌

令牌:

EAAFjVDcBGp4BABSnPzvjeR0ZCqEHExSRIGtvEIMPZCZABh **** fk03WZCg10xaPJUs3ZCZAMTnP8

将令牌设置为Cookie。我想在服务器端访问它,但在服务器上我得到它:

Kk9fbM-3d8ih4SpCfMddsj23BW2bqwPlll9LLs8ZYUE.eyJh **** IjEwNzI4NDM4NjQ0OTI5MiJ9

为什么呢?我该怎么办才能从cookie中获取令牌?

已更新

客户代码:

function checkLoginState() {
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') 
            return;
        FB.login();
    });
}
window.fbAsyncInit = function() {
    FB.init({
        appId: @ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId],
        cookie     : true, 
        xfbml      : true,
        version    : 'v2.8' 
    });
};

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

服务器代码:

var userToken = HttpContext.Current.Request.Cookies[String.Concat("fbsr_", ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId])].Value

1 个答案:

答案 0 :(得分:0)

Cookie不包含access_token

一天后,我在这里找到了解决方案:

Problem getting access_token after migrating to OAuth 2.0