Facebook 与 Asp .Net 集成

发布于 2024-11-15 16:17:34 字数 1928 浏览 2 评论 0原文

我需要将 Facebook 与我的 asp .net 应用程序集成。以下是我为此遵循的步骤。

  1. 我已经从脸书创建了脸书应用程序并获得了应用程序密钥和密钥。
  2. 我已在我的应用程序中使用了该应用程序密钥和秘密密钥。

这是我的代码:

但在这段代码中,“Session[”facebook_userId”]”总是给我空值。你能告诉我原因吗?

protected void Page_Load(对象发送者,EventArgs e) {

    _fbService.ApplicationKey = FACEBOOK_APPKEY;
    _fbService.Secret = FACEBOOK_SECRET;
    _fbService.IsDesktopApplication = false;

    string sessionKey = Session["facebook_session_key"] as String;        
    userId = Session["facebook_userId"] as String;

    // When the user uses the facebook login page, 
    // the redirect back here 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)
    {
        System.Collections.ObjectModel.Collection<User> userinfo = _fbService.GetUserInfo(_fbService.UserId);
        Label1.Text = userinfo[0].FirstName + "'s favorite shops";
        Image1.ImageUrl = userinfo[0].PictureUrl.ToString();

        // Use the FacebookService Component to populate Friends
        System.Collections.ObjectModel.Collection<User> Friends = _fbService.GetFriends();
        for (int i = 0; i < Friends.Count; i++)
            DropDownList2.Items.Add(Friends[i].FirstName.ToString());
    }
}

}

请帮我解决这个问题!

I need to integrate face book with my asp .net application. Here are the steps i have followed for it.

  1. I have created face-book application from face-book and got application key and secret key.
  2. I have used that application key and secret key in my application.

here is my code :

But in this code, "Session["facebook_userId"]" is always giving me null value. can you tell me the reason for this ?

protected void Page_Load(object sender, EventArgs e)
{

    _fbService.ApplicationKey = FACEBOOK_APPKEY;
    _fbService.Secret = FACEBOOK_SECRET;
    _fbService.IsDesktopApplication = false;

    string sessionKey = Session["facebook_session_key"] as String;        
    userId = Session["facebook_userId"] as String;

    // When the user uses the facebook login page, 
    // the redirect back here 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)
    {
        System.Collections.ObjectModel.Collection<User> userinfo = _fbService.GetUserInfo(_fbService.UserId);
        Label1.Text = userinfo[0].FirstName + "'s favorite shops";
        Image1.ImageUrl = userinfo[0].PictureUrl.ToString();

        // Use the FacebookService Component to populate Friends
        System.Collections.ObjectModel.Collection<User> Friends = _fbService.GetFriends();
        for (int i = 0; i < Friends.Count; i++)
            DropDownList2.Items.Add(Friends[i].FirstName.ToString());
    }
}

}

Please help me for this !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も星光 2024-11-22 16:17:34

你用的是哪个工具包??

我建议你使用 codeplex 的 facebooksdk 。是的,正如 Rufinus 所说,对于 Facebook 的每个请求,您都需要 access_token。我在代码中的任何位置都看不到它,

请点击此链接。C# 中的 Facebook Graph API

Which toolkit are you using ??

I suggest you use the facebooksdk from codeplex. And yes as Rufinus says, you will need the access_token for every request to facebook. I cannot see it anywhere in your code

Follow this link instead.. Facebook Graph API in C#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文