2011-06-14 10 views
3

나는 페이스 북 페이지의 fangate 탭 또는 'reveal'탭을 만들기 위해 노력하고있다.사용자가 Facebook 페이지를 좋아하는지 확인합니다.

사용자는 페이지를 방문 할 때 '좋아요'를 클릭하지 않았 으면 한 비트의 콘텐츠가 표시되고 다른 한 번만 클릭하면 콘텐츠가 표시됩니다.

저는 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 
     } 

모든 페이스 북의 설정이 내 web.config 파일에 있고 나는 AppID가와 AppSecret이 올바른지 확인했다.

누구든지 내게이 문제에 대한 통찰력을 제공해 줄 수 있습니까? 내가 아직 찾지 못한 이것을하는 더 좋은 방법이 있습니까?

사전 도움을 주셔서 감사드립니다.

답변

2

그래, 나는 그것을 분류했다. 그러나 나는 이유를 모른다. 페이스 북 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"; 
     } 
1

이것은 내가 사용하는 코드이며 나에게 잘 맞았습니다.

protected bool IsPageLiked() 
    { 
     var current = ConfigurationManager.GetSection("facebookSettings") 
         as IFacebookApplication; 
     dynamic signedRequest = FacebookSignedRequest.Parse(current, Request); 

     try 
     { 
      return signedRequest.Data.page.liked; 
     } 
     catch (Exception) 
     { 
      return false; 
     }  
    } 
+0

VS 2008을 사용하고 있으므로 NuGet 패키지를 참조하기위한 해결 방법을 사용해야합니다. IFacebookApplication 또는 FacebookSignedRequest에 대한 참조를 찾지 못했습니다. 네임 스페이스를 지정할 수 있습니까? 감사! – wloescher

관련 문제