如何使用c#4.0读取签名的请求

| 我正在使用C#4.0,并且正在集成Facebook注册插件 有人可以告诉我阅读签名后的请求该怎么做。 我已经下载了Facebook.dll和Newtonsoft.Json.dll 我也有有效  应用程式编号:*** API密钥:********  应用秘密:************ 如果可能,请给我一个示例代码,我应如何传递这些键以及如何收集以签名请求形式发送的解码数据。 谢谢:     
已邀请:
以下是我所使用的,必须有更简单的方法来读取已签名的请求。只需几个步骤,即可读取C#中的Facebook签名请求 点网2010需要遵循以下步骤。建议您在完成后创建一个名为“ fb”的基于Web的新项目,然后将此代码导入到实际项目中。 从http://facebooksdk.codeplex.com/SourceControl/changeset/view/f8109846cba5#Source%2fFacebook%2fFacebookApp.cs下载源 解压缩后,您将在其中找到“ facebooksdk-f8109846cba5”,在该文件夹中将找到一个文件夹facebooksdk-f8109846cba5 \\ Source \\ Facebook,查找“ Facebook.csproj” 在2010年vs中打开“ Facebook.csproj”。查找文件“ FacebookApp.cs”,打开此文件并搜索“内部受保护的FacebookSignedRequest ParseSignedRequest(stringsignedRequestValue)” 将“内部保护”更改为“公共” 然后通过右键单击项目来构建项目。现在,已编译的文件(“ Facebook.dll”)可以使用了。将其复制到您的项目bin目录中,并添加其引用。 现在从http://json.codeplex.com/releases/view/50552下载Json.Net 3.5版本8,将其添加到项目bin文件夹中,并添加其引用。 现在您可以阅读已签名的请求。现在是时候编写代码来读取已签名的请求了。  
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Facebook;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;

namespace fb
{
    public partial class test3 : System.Web.UI.Page
    {



        protected void Page_Load(object sender, EventArgs e)
        {

            FacebookApp fap = new FacebookApp();


            fap.AppId = \"************\";
            fap.AppSecret = \"********************\";

            string requested_Data = Request.Form[\"signed_request\"];

            FacebookSignedRequest fsr = fap.ParseSignedRequest(requested_Data);


           // string json = JsonConvert.SerializeObject(fsr.Dictionary, Formatting.Indented);


            UserData ud = new UserData(fsr);

            Response.Write(ud.name + \"
\"); Response.Write(ud.birthday + \"
\"); Response.Write(ud.country + \"
\"); Response.Write(ud.email + \"
\"); Response.Write(ud.gender + \"
\"); Response.Write(ud.location + \"
\"); Response.Write(ud.userId + \"
\"); } } public class UserData { public UserData(FacebookSignedRequest fsr) { string value = string.Empty; JObject o; foreach (string key in fsr.Dictionary.Keys) { value = fsr.Dictionary[key]; switch (key) { case \"user_id\": userId = value; break; case \"registration\": o = JObject.Parse(value); name = GetValue(o, \"name\"); birthday = GetValue(o, \"birthday\"); email = GetValue(o, \"email\"); gender = GetValue(o, \"gender\"); location = GetValue(o, \"location.name\"); break; case \"user\": o = JObject.Parse(value); country = GetValue(o, \"country\"); break; } } } private string GetValue(JObject o, string token) { string ret = string.Empty; try { ret = (string)o.SelectToken(token); } catch (Exception ex) { throw ex; } return ret; } public string name { get; set; } public string birthday { get; set; } public string gender { get; set; } public string location { get; set; } public string country { get; set; } public string email { get; set; } public string userId { get; set; } } }
这就是我正在使用的并且对我来说很好。     
这是使用FB C#SDK v.5.2.1.0
var signed_request = Request.Form[\"signed_request\"];

var fap = Facebook.FacebookApplication.Current;
var signed_request_obj = Facebook.FacebookSignedRequest.Parse(fap, signed_request);
if (signed_request_obj != null)
{
  JObject o = JObject.Parse(signed_request_obj.Data.ToString());
}
    

要回复问题请先登录注册