[英]Facebook user email extended permissions with new SDK
我目前在Codeigniter應用程序中使用以下代碼從應用程序用戶獲取Facebook數據。
<?php
require_once('facebook-php-sdk/src/facebook.php');
// Create our Application instance (replace this with your appId and secret).
$facebook= new Facebook(array(
'appId' => '2453463636',
'secret' => '365653656565656',
'allowSignedRequest' => false,
));
$_REQUEST += $_GET;
$user = $facebook->getUser();
if ($user) {
try {
// Get the user profile data you have permission to view
// $user_profile = $facebook->api('/me');
$user_profile = $facebook->api('/me?fields=picture.width(100).height(100),first_name,last_name,username,email');
echo $user_profile['email'];
echo $user_profile['username'];
} catch (FacebookApiException $e) {
$user = null;
}
} else {
die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>');
}
?>
這可以很好地連接並返回頁面上回顯的username
的用戶username
,但是電子郵件不起作用。 在“未定義的索引:電子郵件”視圖上,電子郵件返回顯示為錯誤。
我幾天前用同樣的方法獲取了電子郵件,並且可以正常工作,但是那是在本地主機上。 它在localhost上可以很好地接收電子郵件,當推送到服務器時,它不能識別email
,但是可以識別並獲取username
。
為什么無法識別電子郵件?
我正在使用SDK的最新版本: Facebook PHP SDK(v.3.2.3)
您不能使用此選項。 您需要獲得Facebook的擴展許可。 檢查此鏈接以獲取更多詳細信息:
http://developers.facebook.com/docs/authentication/permissions/
Facebook未經用戶許可不會共享用戶電子郵件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.