FacebookClient访问令牌始终为空

时间:2015-03-19 09:03:09

标签: c# asp.net-mvc-4

我使用以下代码显示facebook的登录对话,成功登录后,它会重定向到我提到的网址。

public ActionResult Index()
{
    dynamic parameters = new ExpandoObject();
        parameters.client_id = appId;
        parameters.redirect_uri = redirectUrl //Home/CompleteFacebookAuth
        parameters.response_type = "token";
        parameters.display = "popup";
        var fb = new FacebookClient();

        return Redirect(fb.GetLoginUrl(parameters));
}

CompleteFacebookAuth操作方法存在问题,令牌始终为空。

public ActionResult CompleteFacebookAuth(string token)
{

        var fb = new FacebookClient(token);
        dynamic result = fb.Get("me");

}

任何想法?

更新:这是网址

http://localhost:8399/Home/CompleteFacebookAuth?code=AQBb4tT_n7JPbNqSIVKovkNlKQBTNxpt3sIsPo0wOPyGbuQVHdFCMaH_MqcqosqnwEEso1tclhtGBEgBadxEeUHHtEuKQY2sqiN5LtoIm-JZjp8QlaDxTfQsGMiz4uGA4_Nn4nRX-nW0mIAvGMh-1VET8Hs544he2-DOG0l56ftcsEk9h8rUGNjHwPNT6EbLaFWA74h2dXkiNCwsizqCLnbHuBfaftIzpUPX8DJOBK0nFVD0sVeVR8MLZiGqaa82JhehBTqXVb4uX0tGOxGQCy_Rn88inW2cInled6S18z0ptbLXYl1J92Ne_RP_xZKDunY#=

1 个答案:

答案 0 :(得分:0)

令牌存储在查询字符串中,您只需更改控制器方法的参数名称即可映射令牌。这样可以正常工作。

public ActionResult CompleteFacebookAuth(string code)
{

    var fb = new FacebookClient(code);
    dynamic result = fb.Get("me");

}