我正在使用Facebook C# SDK并试图弄清楚它是如何工作的 . 我实际上使用AJAX Web方法根据经过身份验证的用户ID查找Facebook帐户详细信息,如下所示:
if (response.status === "connected")
{
KitchenPC.LogonFB(response.authResponse.userID, checkResult, facebookError);
}
在服务器端,LogonFB Web方法执行以下操作:
Client = new FacebookClient(applicationId, applicationSecret);
var result = Client.Get(path) as IDictionary<string, object>;
UserId = Int64.Parse((String)result["id"]);
Name = result["name"] as String;
FirstName = result["first_name"] as String;
LastName = result["last_name"] as String;
Location = result.ContainsKey("location") ? result["location"] as String : "";
Gender = result.ContainsKey("gender") ? result["gender"] as String : "";
Email = result["email"] as String;
path
是从客户端传入的用户ID .
My Question:
我正在从ASP.NET Web Service切换到WCF,而WCF不支持cookie . 实际上, HttpContext.Current
在WCF管道中将为null . 我的印象是Facebook C#SDK依赖于在请求中传递的 fbm_
和 fmsr_
cookie,这将用于验证与Facebook服务器的会话 . 但是,令我惊讶的是, .Get()
调用仍然有效,并返回用户信息 . 我还挖掘了SDK源代码并且在其中找不到 HttpContext.Current
的引用 .
Facebook C#SDK是否完全独立于cookie?这是否意味着我所需要的只是用户的Facebook ID,只要他们之前已经批准我的应用ID,我就可以获取有关其帐户的信息?
我只是想确保我没有做错任何事,我不会在 生产环境 中遇到麻烦 .
1 回答
当您使用appId和appSecret传递构造函数时,它将使用
string.Concat(appId, '|', appSecret)
自动将访问令牌设置为app访问令牌 . 该构造函数已在较新版本的sdk中删除 . https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues/103如果您不想要访问令牌,请将其设置为null .