邮政地位的Facebook个人资料,而无需使用ASP.NET Facebook的模式窗口 [英] Post status to Facebook profile without Facebook modal window using ASP.NET

查看:126
本文介绍了邮政地位的Facebook个人资料,而无需使用ASP.NET Facebook的模式窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的ASP.NET网站,在这里我有一个在我的网站文字为他们在我的网站地位框中输入的用户登录与Facebook合作。我希望他们能够这种地位推到FB,以及根据他们的权限。我这样做是使用简单的Facebook连接JS code,但我想在.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.

这是伪code,因为我想要的东西:

This is pseudo-code for what I want:

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或是他们的PHP API只?

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

推荐答案

当然,这里是一些示例code。它使用Facebook开发工具包(你可以找到它的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验证步骤是很重要的。

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 code,这是在JS设置相同的cookie是在C#中访问。

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

这对于Facebook连接的应用程序工作正常。

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;
        }

这篇关于邮政地位的Facebook个人资料,而无需使用ASP.NET Facebook的模式窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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