我正在尝试为Facebook页面构建Facebook“fangate”标签或“显示”标签。
你知道它是怎么回事 - 当用户访问该页面时,如果他们还没有点击“喜欢”,则会显示一些内容。
我不是一个PHP人,所以我试图在Visual Studio 2010中使用Facebook C#SDK( http://facebooksdk.codeplex.com )。我也是.NET的新手,所以我不是做得好!
我不得不承认我一直在剪切和粘贴来自各地的代码以使其工作,我想我几乎就在那里,但我没有收到这个错误:
签名请求无效。
第82行:var DecodedSignedRequest = FacebookSignedRequest.Parse(current,FacebookWebContext.Current.SignedRequest.Data.ToString());
这是我的代码:
var settings = ConfigurationManager.GetSection("facebookSettings"); var current = settings as IFacebookApplication; var DecodedSignedRequest = FacebookSignedRequest.Parse(current, FacebookWebContext.Current.SignedRequest.Data.ToString()); dynamic SignedRequestData = DecodedSignedRequest.Data; var RawRequestData = (IDictionary<string, object>)SignedRequestData; string currentFacebookPageID = current.AppId; bool currentFacebookPageLiked = false; if (RawRequestData.ContainsKey("page") == true) { Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"]; if (RawPageData.ContainsKey("id") == true) currentFacebookPageID = (string)RawPageData["id"]; if (RawPageData.ContainsKey("liked") == true) currentFacebookPageLiked = (bool)RawPageData["liked"]; } if (currentFacebookPageLiked) { //Do some stuff for fans } else { //Do some stuff for non-fans }所有的Facebook设置都在我的web.config文件中,我已经检查过AppID和AppSecret是否正确。
任何人都可以向我提供有关此问题的任何见解吗? 有没有更好的方法来做到这一点,我还没有找到?
非常感谢您的帮助。
I'm trying to build a Facebook 'fangate' tab or 'reveal' tab for a Facebook page.
You know how it goes - when a user visits the page, they are shown one bit of content if they haven't yet clicked 'Like' and another once they have.
I'm not a PHP guy so I'm attempting to do this with the Facebook C# SDK (http://facebooksdk.codeplex.com) in Visual Studio 2010. I'm fairly new to .NET too so I'm not doing so well with this!
I have to admit I've been cutting and pasting code from all over the place to get this to work and I think I'm almost there but I'm not getting this error:
Invalid signed request.
Line 82: var DecodedSignedRequest = FacebookSignedRequest.Parse(current, FacebookWebContext.Current.SignedRequest.Data.ToString());
Here's my code:
var settings = ConfigurationManager.GetSection("facebookSettings"); var current = settings as IFacebookApplication; var DecodedSignedRequest = FacebookSignedRequest.Parse(current, FacebookWebContext.Current.SignedRequest.Data.ToString()); dynamic SignedRequestData = DecodedSignedRequest.Data; var RawRequestData = (IDictionary<string, object>)SignedRequestData; string currentFacebookPageID = current.AppId; bool currentFacebookPageLiked = false; if (RawRequestData.ContainsKey("page") == true) { Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"]; if (RawPageData.ContainsKey("id") == true) currentFacebookPageID = (string)RawPageData["id"]; if (RawPageData.ContainsKey("liked") == true) currentFacebookPageLiked = (bool)RawPageData["liked"]; } if (currentFacebookPageLiked) { //Do some stuff for fans } else { //Do some stuff for non-fans }All the Facebook settings are in my web.config file and I have checked that the AppID and AppSecret are correct.
Can anyone offer me any insight into this issue please? Is there a better way of doing this that I've not yet found?
Many thanks in advance for any help.
最满意答案
好的,我把它整理出来 - 但我不确定为什么。 我有一种感觉,Facebook C#SDK以某种方式解决了签名请求。 如果我使用Request.Forms [“signed_request”]获得签名请求,那么一切似乎都有效。
我将分享我的工作代码,希望它能帮助其他人解决同样的问题。
//Pull in the facebook app settings from the web.config file var settings = ConfigurationManager.GetSection("facebookSettings"); var current = settings as IFacebookApplication; //Set up some stuff for later string currentFacebookPageID = current.AppId; bool currentFacebookPageLiked = false; //Get the signed request FacebookSignedRequest SignedRequest = FacebookSignedRequest.Parse(current, Request.Form["signed_request"]); dynamic SignedRequestData = SignedRequest.Data; //extract what we need from the request var RawRequestData = (IDictionary<string, object>)SignedRequestData; //Check to see if we've got the data we need if (RawRequestData.ContainsKey("page") == true) { //We do, lets examine it and set the boolean as appropriate Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"]; if (RawPageData.ContainsKey("id") == true) currentFacebookPageID = (string)RawPageData["id"]; if (RawPageData.ContainsKey("liked") == true) currentFacebookPageLiked = (bool)RawPageData["liked"]; } if (currentFacebookPageLiked) { //Do some stuff for fans lblName.Text = "Hi " + result.first_name + " - You are a fan"; } else { //Do some stuff for non-fans lblName.Text = "Hi " + result.first_name + " - please click the like button"; }OK, I've sorted it out - but I'm not sure why. I have a feeling that the Facebook C# SDK screws around with the signed request in some way. If I get the signed request using Request.Forms["signed_request"] it all seems to work.
I'll share my working code in the hope that it will help others with the same problem.
//Pull in the facebook app settings from the web.config file var settings = ConfigurationManager.GetSection("facebookSettings"); var current = settings as IFacebookApplication; //Set up some stuff for later string currentFacebookPageID = current.AppId; bool currentFacebookPageLiked = false; //Get the signed request FacebookSignedRequest SignedRequest = FacebookSignedRequest.Parse(current, Request.Form["signed_request"]); dynamic SignedRequestData = SignedRequest.Data; //extract what we need from the request var RawRequestData = (IDictionary<string, object>)SignedRequestData; //Check to see if we've got the data we need if (RawRequestData.ContainsKey("page") == true) { //We do, lets examine it and set the boolean as appropriate Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"]; if (RawPageData.ContainsKey("id") == true) currentFacebookPageID = (string)RawPageData["id"]; if (RawPageData.ContainsKey("liked") == true) currentFacebookPageLiked = (bool)RawPageData["liked"]; } if (currentFacebookPageLiked) { //Do some stuff for fans lblName.Text = "Hi " + result.first_name + " - You are a fan"; } else { //Do some stuff for non-fans lblName.Text = "Hi " + result.first_name + " - please click the like button"; }更多推荐
发布评论