我正在使用c#4.0,我正在整合facebook註冊插件 有人可以告訴我我需要做什麼才能閱讀已簽名的請求。 我已經下載Facebook.dll和Newtonsoft.Json.dll 我也有有效 應用程序ID:* ** API密鑰:* ** * ** * *** 應用揭祕: ** * ** * ** * **** 如果可能的話p租賃給我一個示例代碼,我應該如何通過這些關鍵字,以及如何收集以簽名請求形式發送的解碼數據。如何使用c#4.0讀取簽名的請求
感謝:
我正在使用c#4.0,我正在整合facebook註冊插件 有人可以告訴我我需要做什麼才能閱讀已簽名的請求。 我已經下載Facebook.dll和Newtonsoft.Json.dll 我也有有效 應用程序ID:* ** API密鑰:* ** * ** * *** 應用揭祕: ** * ** * ** * **** 如果可能的話p租賃給我一個示例代碼,我應該如何通過這些關鍵字,以及如何收集以簽名請求形式發送的解碼數據。如何使用c#4.0讀取簽名的請求
感謝:
必須有更多的簡便的方法來閱讀以下是我所使用簽名的請求。在c#中閱讀Facebook簽名請求的步驟很少。
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; }
}
}
Shahid,你很好回答你自己的問題。請注意,你也可以接受它。這樣,每個人都會看到你的問題得到了回答。 – Marijn 2011-06-03 07:21:51
這裏使用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());
}
[讀取的OAuth2.0 Signed_Request登記的Facebook C#MVC(的
可能重複http://stackoverflow.com/questions/4575932/read-oauth2-0-signed-request-facebook-registration-c-mvc) – bkaid 2011-05-26 14:33:55