使用 ASP.NET 在没有 Facebook 模式窗口的情况下将状态发布到 Facebook 个人资料 [英] Post status to Facebook profile without Facebook modal window using ASP.NET

查看:21
本文介绍了使用 ASP.NET 在没有 Facebook 模式窗口的情况下将状态发布到 Facebook 个人资料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 ASP.NET 站点中与 Facebook 合作,我的站点的登录用户在该站点中的文本框中输入了他们在我站点上的状态.我希望他们也能够根据他们的许可将该状态推送到 FB.我使用简单的 Facebook Connect JS 代码做到了,但我想在 .NET 中获取信息并以这种方式推送.不过,我实际上并没有为 FB 个人资料创建 FB 应用程序.

I'm trying to work with Facebook in my ASP.NET site where I have a logged in user of my site enter in text in a box for their status on my site. I want them to be able to push that status to FB as well per their permission. I did it using simple Facebook Connect JS code but I want to get the info in .NET and push it that way. I'm not actually creating a FB app for a FB profile though.

这是我想要的伪代码:

Facebook fb = new Facebook(apiKey);
FBSession sess = fb.Authenticate();
if(sess.isAuthenticated) {
  User u = fb.getUser(sess.userId);
  u.setStatus(Textbox1.text);
  u.SaveStatus();
}

.NET 是否存在这样的东西,还是它们的 API 仅适用于 PHP?

Does anything like this even exist for .NET or is their API for PHP only?

推荐答案

当然,这里有一些示例代码.它使用 Facebook Developer Toolkit(您可以在 codeplex 上找到它).还有 FBConnectAuth 也可以在 codeplex 上找到.

Sure, here is some sample code. It's using the Facebook Developer Toolkit (you can find it on codeplex). And FBConnectAuth which can also be found on codeplex.

您想检查 cookie 以确保 cookie 是真实的(确保没有人试图入侵);这就是 cookie 验证步骤很重要的原因.

You want to check the cookies to make sure that the cookie is real (making sure someone is not trying to hack in); which is why the cookie validation step is important.

只要使用JS代码登录,在C#中可以访问与JS中设置的相同的cookie.

As long as you login using the JS code, the same cookies that are set in the JS are accessible in C#.

这适用于 Facebook Connect 应用.

This works fine for a Facebook Connect app.

        using FBConnectAuth;
        using facebook;

        public facebook.API api = new facebook.API();

        bool IsLoggedInToFacebook = false;
        FBConnectAuthentication auth = new FBConnectAuthentication(ConfigurationManager.AppSettings["AppKey"], ConfigurationManager.AppSettings["Secret"]);
        if (auth.Validate() != ValidationState.Valid)
        {
            IsLoggedInToFacebook = false;
        }
        else
        {
            FBConnectSession fbSession = auth.GetSession();
            string userId = fbSession.UserID;
            string sessionKey = fbSession.SessionKey;

            api.ApplicationKey = ConfigurationManager.AppSettings["AppKey"];
            api.SessionKey = sessionKey;
            api.Secret = ConfigurationManager.AppSettings["Secret"];
            api.uid = Convert.ToInt64(userId);
            api.status.set("statutes text goes here")

            IsLoggedInToFacebook = true;
        }

这篇关于使用 ASP.NET 在没有 Facebook 模式窗口的情况下将状态发布到 Facebook 个人资料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆