How to get the top URL from a Facebook application?

后端 未结 4 1018
青春惊慌失措
青春惊慌失措 2021-01-25 15:02

How can I get the top URL (Facebook\'s address) in my iframe application?

Is there a good solution on that?

4条回答
  •  面向向阳花
    2021-01-25 15:38

    You can probably figure this out from the "signed_request" POST parameter that Facebook sends to apps loaded within pages.

    In PHP that's:

    $_POST["signed_request"]
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    $page_id = $data["page"]["id"];
    

    If you want to prevent technical users from being able to spoof the parent page's identity, you can validate the $encoded_sig; this is probably overkill, however.

    The $page_id is just a number, so you'll need to use other Facebook APIs (or make a call to "http://www.facebook.com/pages/k/$page_id" and see where you're redirected to) to get the full URL.

提交回复
热议问题