2012-12-25 24 views
0

使用Facebook PHP SDK。我跟着一个教程之后,跑进一个问题,得到这个页面加载,这将是错误,我得到:

screenshot of error

下面是代码(应用程序ID和秘密密钥已被删除) 。我从教程中获得了该文件,并从GitHub上提供的文件中填入了一些内容。

<?php 

require 'src/facebook.php' 

$app_id = ""; // has been removed 
$secret = ""; // has been removed 
$app_url = "http://apps.facebook.com/instahomework/"; 

// Create our Application instance (replace this with your appId and secret). 
$facebook = new Facebook(array(
    'appId' => $app_id, 
    'secret' => $secret, 
)); 

// Get User ID 
$user = $facebook->getUser(); 

// We may or may not have this data based on whether the user is logged in. 
// 
// If we have a $user id here, it means we know the user is logged into 
// Facebook, but we don't know if the access token is valid. An access 
// token is invalid if the user logged out of Facebook. 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(); 

// This call will always work since we are fetching public data. 
$naitik = $facebook->api('/naitik'); 

?> 
<!doctype html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
<title>php-sdk example 1 - user login and authorisation</title> 
<style> 
body { font-family: Helvetica, Verdana, Arial, sans-serif; } 
a { text-decoration:none; } 
a:hover { text-decoration:underline; } 
</style> 
</head> 
<body> 
<pre> 
<?php print_r($_REQUEST); ?> 
</pre> 
    <?php if ($user) { ?> 
     <h2>Welcome</h2> 
     <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"><br/> 
     <a href="<?php echo $link; ?>"><?php echo $name; ?></a><br/> 
     <br/> 
     Gender : <?php echo $gender; ?><br/> 
     Locale : <?php echo $locale; ?><br/> 
     Username : <?php echo $username; ?><br/> 
    <?php } else { ?> 
     <strong><em>You have not granted this App permission to access your data. Redirecting to permissions request...</em></strong> 
<?php } ?> 
</body> 
</html> 
+1

添加了''之后}自动显示这些类型的错误' $ loginUrl = $ facebook-> getLoginUrl();'终止'else'。 – DCoder

回答

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

一个括号缺失,我会建议你使用Eclipse IDE,对于这样的错误,它会在编写代码时

+0

好的,谢谢,是的,我在Sublime上,所以我会研究Eclipse。 – JGallardo

相关问题