Facebook Connect 和 ASP.NET
我位于此处找到的身份验证概述的第 8 步:http://wiki.developers。 facebook.com/index.php/How_Connect_Authentication_Works
特别是,用户已通过 Facebook Connect 登录 facebook,并且其 Web 会话已创建。 如何使用 facebook 开发者工具包 v2.0(为了清晰起见)来检索有关用户的信息。 例如,我想获取用户的名字和姓氏。
文档中的示例适用于 Facebook 应用程序,但事实并非如此。
更新
Facebook 最近发布了 Graph API。 除非您正在维护使用 Facebook Connect 的应用程序,否则您应该查看最新的 API:http://developers。 facebook.com/docs/
I'm at step 8 of the authentication overview found here: http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works
In particular, the user has logged into facebook via Facebook Connect and their web session has been created. How do I use the facebook developer toolkit v2.0 (from clarity) to retrieve information about the user. For example, I'd like to get the user's first name and last name.
Examples in the documentation are geared towards facebook applications, which this is not.
Update
Facebook recently released the Graph API. Unless you are maintaining an application that is using Facebook Connect, you should check out the latest API: http://developers.facebook.com/docs/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我跟进了 Bill 的精彩文章,并制作了这个小组件。 它负责通过 Facebook Connect cookie 识别和验证用户。
Facebook Connect 身份验证 for ASP.NET
我希望对某人有所帮助!
干杯,
亚当
I followed up from Bill's great article, and made this little component. It takes care of identifying and validating the user from the Facebook Connect cookies.
Facebook Connect Authentication for ASP.NET
I hope that helps somebody!
Cheers,
Adam
您还可以使用 SocialAuth.NET
它提供与 facebook、google 的身份验证、个人资料和联系人、MSN 和 Yahoo 的开发工作很少。
You may also use SocialAuth.NET
It provides authentication, profiles and contacts with facebook, google, MSN and Yahoo with little development effort.
我的两分钱:一个利用“使用 Facebook 登录”功能的非常简单项目 - facebooklogin.codeplex。 com
不是一个库,但展示了它是如何工作的。
My two cents: a very simple project utilizing the "login with Facebook" feature - facebooklogin.codeplex.com
Not a library, but shows how it all works.
当用户使用 Facebook Connect 登录后,我很难弄清楚如何进行服务器端调用。 关键在于,一旦成功登录,Facebook Connect javascript 就会在客户端上设置 cookie。 您使用这些 cookie 的值在服务器上执行 API 调用。
令人困惑的部分是查看他们发布的 PHP 示例。 他们的服务器端 API 自动负责读取这些 cookie 值并设置一个 API 对象,该对象已准备好代表登录用户发出请求。
以下是用户使用 Facebook Connect 登录后在服务器上使用 Facebook Toolkit 的示例。
服务器代码:
Utility.cs
I had a lot of trouble figuring out how to make server side calls once a user logged in with Facebook Connect. The key is that the Facebook Connect javascript sets cookies on the client once there's a successful login. You use the values of these cookies to perform API calls on the server.
The confusing part was looking at the PHP sample they released. Their server side API automatically takes care of reading these cookie values and setting up an API object that's ready to make requests on behalf of the logged in user.
Here's an example using the Facebook Toolkit on the server after the user has logged in with Facebook Connect.
Server code:
Utility.cs
我跟进了这个概念并写了一篇完整的文章来解决 ASP.NET 中的这个问题。 请看以下内容。
如何检索用户数据来自 ASP.NET 中的 Facebook Connect - Devtaulous
感谢 Calebt 在该帮助程序类上提供了良好的开端。
享受。
I followed up on this concept and wrote a full fledged article that solves this problem in ASP.NET. Please see the following.
How to Retrieve User Data from Facebook Connect in ASP.NET - Devtacular
Thanks to Calebt for a good start on that helper class.
Enjoy.
Facebook Connect 实际上并不太难,只是缺少文档。
将此处中的必要 javascript
验证 cookie 是否与 facebook 提供的签名相匹配防止黑客攻击,请参阅此了解如何开始
创建 api对象(Facebook.API.FacebookAPI)
在 api 对象上,设置应用程序密钥和 Facebook 在创建应用程序时为您提供的秘密。
从 facebook connect 为您创建的 cookie 设置
api.SessionKey
和api.UserId
。完成后,您可以开始拨打 Facebook 电话:
Facebook Connect actually isn't too difficult, there's just a lack of documentation.
Put the necessary javascript from here
Validate the cookies match the signature provided by facebook to prevent hacking, see this for an explanation on how to get started
Create an api object (Facebook.API.FacebookAPI)
On the api object, set the application key and secret Facebook provides you when you create your app.
Set
api.SessionKey
andapi.UserId
from the cookies created for you from facebook connect.Once that is done, you can start making calls to facebook:
到目前为止列出的答案中缺少这一点:
登录成功后,Facebook 建议您验证 cookie 是否确实合法并由它们放置在客户端计算机上。
这里有两种方法可以一起使用来解决这个问题。 您可能想要将 IsValidFacebookSignature 方法添加到 calebt 的 Utility 类中。 请注意,我也稍微更改了他的 GetFacebookCookie 方法。
SecretKey 和 ApiKey 是 Facebook 向您提供的值。 在这种情况下,需要设置这些值,最好来自 .config 文件。
This is missing from the answers listed so far:
After login is successful, Facebook recommends that you validate the cookies are in fact legit and placed on the client machine by them.
Here is two methods that can be used together to solve this. You might want to add the IsValidFacebookSignature method to calebt's Utility class. Notice I have changed his GetFacebookCookie method slightly as well.
The SecretKey and ApiKey are values provided to you by Facebook. In this case these values need to be set, preferably coming from the .config file.