[英]Facebook app not retrieving user info
我剛剛使用Facebook PHP SDK構建了一個應用程序並進行了設置。 我正在測試它,盡管我的個人資料中顯示了該圖像,但是未顯示所請求的用戶信息。 這是結果的屏幕截圖
這是我上傳到服務器的php代碼。 請注意,App ID和Secret已從此處刪除。
<?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();
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>
您應該將HTML代碼替換為:
<h2>Welcome</h2>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture"><br/>
<a href="<?php echo $user_profile['link']; ?>"><?php echo $user_profile['name']; ?></a><br/>
<br/>
Gender : <?php echo $user_profile['gender']; ?><br/>
Locale : <?php echo $user_profile['locale']; ?><br/>
Username : <?php echo $user_profile['username']; ?><br/>
這行代碼要求您輸入“用戶信息”:
$user_profile = $facebook->api('/me');
並存儲到$user_profile
數組中。
另一個解決方法(但不推薦)是使用extract()
通過添加以下代碼行將數據從facebook提取到全局變量范圍中:
extract($user_profile);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.