How to get the Page Id in my Facebook Application page

后端 未结 3 1188
挽巷
挽巷 2021-02-11 02:10

I have my application is hosted in FaceBook as a tab and I want to get the page ID when my application is being added to be stored in my logic. How can I get the page ID, I kno

3条回答
  •  [愿得一人]
    2021-02-11 02:58

    The Page ID is not stored in the URL; it is posted to your page within the signed_request form parameter. See this Facebook developer blog post for more details.

    You can use the FacebookSignedRequest.Parse method within the Facebook C# SDK to parse the signed request (using your app secret). Once you have done this you can extract the Page ID from the Page JSON object as follows:

    string signedRequest = Request.Form["signed_request"];
    
    var DecodedSignedRequest = FacebookSignedRequest.Parse(FacebookContext.Current.AppSecret, SignedRequest);
    dynamic SignedRequestData = DecodedSignedRequest.Data;
    
    var RawRequestData = (IDictionary)SignedRequestData;
    
    if (RawRequestData.ContainsKey("page") == true)
    {
        Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"];
        if (RawPageData.ContainsKey("id") == true)
             currentFacebookPageID = (string)RawPageData["id"];
    }
    

    Hope this helps.

提交回复
热议问题