PHP SDK: How do I capture the access token after user auths app?

后端 未结 4 864
遥遥无期
遥遥无期 2020-12-18 16:26

This is for a canvas app on the Facebook Platform using the new(est) Facebook PHP SDK.

We are using the PHP example from the Facebook tutorial (https://developers.fa

4条回答
  •  悲哀的现实
    2020-12-18 17:13

    Problem

    The access_token in your pasted URL is not part of the query string, but instead contained in the URL fragment (after the #). URL fragments are not sent to the web server, and are readable only by client-side code like Javascript. Therefore the PHP SDK only sees http://karmakorn.com/karmakorn/alpha20/kk-fb-auth.php, which is why $_REQUEST does not contain an access_token key.

    Questions / Notes

    1. What are you using for your redirect_uri? I think you want to be using something like http://apps.facebook.com/your_canvas_url/
    2. You shouldn't need to call parse_signed_request yourself or copy any code from the signed request page. The PHP SDK will do that for you. Just call:

      $facebook = new Facebook(array(
          'appId' => '…',
          'secret' => '…',
      ));
      $access_token = $facebook->getAccessToken();
      

    Possible solutions

    1. Also use the Facebook Javascript SDK. You can start by adding its
提交回复
热议问题