面对facebook中的问题使用asp.net连接api

时间:2010-08-24 05:56:53

标签: asp.net facebook


我正在使用Facebook连接API来抓住我的朋友列表。它将我重定向到登录页面。
但是当我提供凭据时,它会抛出类似这样的错误;

API Error Code: 100
API Error Description: Invalid parameter
Error Message: Requires valid next URL.

这是代码;

//my actual values are mentioned in the key

_fbService.ApplicationKey = "KEY";
        _fbService.Secret = "Key";
        _fbService.IsDesktopApplication = false;
        string sessionKey = Session["Facebook_session_key"] as String;
        string userId = Session["Facebook_userId"] as String;



        // When the user uses the Facebook login page, the redirect back here will will have the auth_token in the query params
        string authToken = Request.QueryString["auth_token"];
        if (!String.IsNullOrEmpty(sessionKey))
        {
            _fbService.SessionKey = sessionKey;
            _fbService.UserId = userId;
        }
        else if (!String.IsNullOrEmpty(authToken))
        {
            _fbService.CreateSession(authToken);
            Session["Facebook_session_key"] = _fbService.SessionKey;
            Session["Facebook_userId"] = _fbService.UserId;
            Session["Facebook_session_expires"] = _fbService.SessionExpires;
        }
        else
        {
            Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + @"&v=1.0");
        }

        if (!IsPostBack)
        {
            // Use the FacebookService Component to populate Friends
            //MyFriendList.Friends = _fbService.GetFriends();
             MyFriendlist.Friends = _fbService.GetFriends();
        }

有谁知道怎么摆脱这个? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

请尝试使用

,而不是重定向到网址

base.login = TRUE;

// Response.Redirect(@“http://www.Facebook.com/login.php?api_key=”+ _fbService.ApplicationKey + @“& v = 1.0”);

Response.Redirect(@“http://www.Facebook.com/login.php?api_key=”+ _fbService.ApplicationKey + @“& v = 1.0& next = http://apps.facebook.com/yourapplication”);