阅读 OAuth2.0 Signed_Request Facebook 注册 C# MVC
我的问题非常相似这个 但我想我需要更进一步。
Facebook 表示,“数据作为签名请求传递到您的应用程序。signed_request 参数是确保您收到的数据是 Facebook 发送的实际数据的简单方法。”
用户登录我的 asp c# MVC 站点并单击“注册”后,重定向 URL 为 http://site/帐户/注册。那时(发布到帐户/注册控件),我想使用签名的请求收集用户的信息,以便我可以在本地站点上注册它们。我不知道如何访问 Facebook 提供的数据。
$data = json_decode(base64_url_decode($payload), true);
C# 中的等价物是什么? Facebook 在帖子中传递什么类型的变量/数据?我如何访问“$payload”?
[HttpPost]
public ActionResult RegisterFacebook(RegisterFacebookModel model)
{
Facebook.FacebookSignedRequest sr = Facebook.FacebookSignedRequest.Parse("secret", model.signed_request);
return View(model);
}
My question is very similar this but I guess I need to take it one step further.
Facebook says "The data is passed to your application as a signed request. The signed_request parameter is a simple way to make sure that the data you're receiving is the actual data sent by Facebook."
After a user has logged into my asp c# MVC site and clicked "Register", the redirect-url is http://site/account/register. At that point (the post to the account/register control), I would like to gather the user's information using the signed request so that I can register them with my site locally. I cannot figure out how to access the data facebook makes available.
$data = json_decode(base64_url_decode($payload), true);
What is the equivalent in C#? What type of variable/data is facebook passing in the post? And how do I access "$payload"?
[HttpPost]
public ActionResult RegisterFacebook(RegisterFacebookModel model)
{
Facebook.FacebookSignedRequest sr = Facebook.FacebookSignedRequest.Parse("secret", model.signed_request);
return View(model);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我们在 Facebook C# SDK 中使用的代码。如果您使用我们的 sdk,则不需要手动执行此操作,但如果您需要自己执行此操作,则为:
您可以在此处找到完整的源代码:http://facebooksdk.codeplex.com/SourceControl/changeset/view/f8109846cba5#Source%2fFacebook%2fFacebookApp.cs
Here is the code we used in the Facebook C# SDK. You don't need to do this manually if you use our sdk, but if you need to do it yourself here it is:
You can find the full source code here: http://facebooksdk.codeplex.com/SourceControl/changeset/view/f8109846cba5#Source%2fFacebook%2fFacebookApp.cs
根据您的评论,您似乎仍在寻找 FB 发送的回复。我相信它包含在 HttpContext Request 对象的 Form 集合中。因此,从您指定为重定向的页面中,您应该能够从以下位置提取它:
HttpContext.Current.Request.Form("signed_request")
希望这有助于阐明一些内容。我仍在不断学习,所以这可能不是最好的解决方案。
谢谢,
贾森
Based on your comment, it looks like you're still looking for the response that FB is sending. I believe it it contained in the Form collection in the HttpContext Request object. So from the page you specify as the redirect, you should be able to pull it from:
HttpContext.Current.Request.Form("signed_request")
Hope that helps shed some light. I'm still learning as I go so this may not be the best solution.
thanks,
Jason
以下是如何使用 Facebook SDK 执行此操作
Here's how to do it using Facebook SDK