开发者

Facebook App Development - Authentication using Dialog API using PHP

开发者 https://www.devze.com 2023-03-01 16:33 出处:网络
I\'m trying to integrate my web application with the Facebook platform. below is my test code, if ($_REQUEST[\'error_reason\']) {echo(\"<script> top.location.href=\'ht开发者_开发知识库tp://f

I'm trying to integrate my web application with the Facebook platform.

below is my test code,

 if ($_REQUEST['error_reason']) {  echo("<script> top.location.href='ht开发者_开发知识库tp://facebook.com'</script>"); }
else {  
    $app_id = "APP_CODE";
    $canvas_page = "https://e3xcp.com/hs/fb/";
    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page) "&scope=email,user_birthday,user_hometown,user_location,user_religion_politics,user_website,user_checkins";

    $signed_request = $_REQUEST["signed_request"];
    list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    if (empty($data["user_id"])) {
          echo("<script> top.location.href='" . $auth_url . "'</script>");
    } else {
          echo ("Welcome User: " . $data["user_id"] . "<BR><BR>");
          print_r($data);
          echo "<BR><BR>". $data['oauth_token'] . "<BR><BR>";

          $graph_url = "https://graph.facebook.com/me?access_token=". trim($data['oauth_token']); 
          $json_data = file_get_contents($graph_url);
          $me = json_decode($json_data);
          echo $me->id;
    }
} 

There are two issues,

  1. When Authenticating (a new user), when the user press "Allow" button, the browser navigates back and forth between my canvas page and the facebook server.

  2. When an authenticated user accessed the app, i get an error saying,

    **> Warning: file_get_contents(https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo) [function.file-get-contents]: failed to open stream: No error in C:\Inetpub\vhosts\E3XCP.COM\httpdocs\hs\FB\index.php on line 19**
    

But when I copy and paste the GRAPH URL

  ***https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo*** it returns the correct output

There are two authentication samples given in the Facebook Developers documentation and i tried both methods.

The app link is http://apps.facebook.com/slhoroscope Help !!!


  1. You need to use the Canvas Page and not the Canvas Url, i.e $canvas_page = "http://apps.facebook.com/slhoroscope/";
  2. It has something to do with your PHP configuration, most likely the openssl extension.
0

精彩评论

暂无评论...
验证码 换一张
取 消