简体   繁体   中英

Facebook SDK PHP Blank Page

I started programming a new Facebook App for my Webpage.
I own a valid HTTPS / SSL Cert for this App setted the configs. PHP and Apache is running.

The Problem:
When I try to run a simple Facebook php script, it shows me a blank page with no content. I uploaded for example the facebook example.php and it still shows a blank page when i open the page. The APP secret and APP ID is setted correctly.

Does anybody has an suggestion for me?

EDIT:

    <?php

require '/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'xxxx(appid)',
  'secret' => 'xxxx(secret)',
));

$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

$naitik = $facebook->api('/naitik');

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>php-sdk</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>php-sdk</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">

      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_profile); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>

    <h3>Public profile of Naitik</h3>
    <img src="https://graph.facebook.com/naitik/picture">
    <?php echo $naitik['name']; ?>
  </body>
</html>

This Code is from https://github.com/facebook . Its the example.php which isn't working.

This example should show you Naitik's picture regardless of whether you set the app_id or app_secret correctly. If it doesn't, it means that your example.php file was not setup correctly or there's something wrong with your server.

What is the PHP error you get when you load the page?

-- EDIT --

Refer to this post for the solution: OAuth Error: This IP can't make requests for that application

Maybe your mobile solution is out of your facebook app's allowed domain/subdomain? By that I mean, perhaps you set your app domain as "something.com" but you're trying to invoke the login url from "mobile.something.com", that would be a valid reason to display a blank page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM