获取Facebook用户个人资料数据在php [英] Get Facebook user profile data in php
问题描述
以下代码应该返回已登录用户的电子邮件地址。
<?php
require_once('facebook-php-sdk / src / facebook.php');
//创建我们的应用程序实例(将其替换为您的appId和密钥)。
$ facebook = new Facebook(array(
'appId'=>'2453463636',
'secret'=>'365653656565656',
'allowSignedRequest'=& false,
));
$ user = $ facebook-> getUser();
print_r($ user);
if($ user){
try {
//获取您有权查看的用户个人资料数据
// $ user_profile = $ facebook-> api我');
$ user_profile = $ facebook-> api('/ me?fields = picture.width(100).height(100),first_name,last_name,username,email'
echo $ user_profile ['email'];
} catch(FacebookApiException $ e){
$ user = null;
error_log($ e);
print_r($ e);
}
} else {
die(failed);
}
?>
而是返回failed,print_r($ user)返回0。
真的不知道该怎么办。
在仪表板中:
>
设置一个网站平台来查看我的应用程序。
jist:
App Domains= / code>
Site Url= http://www.app.com/test
网站网址是实际的应用程式。我尝试访问网址中的 getUser
,例如 http://www.app.com/test/fbuser
EDIT
/ strong>我的本地主机服务器上的卷轴
配置命令是完全不同的(见下面localhost屏幕截图)
>
远程服务器在配置命令的文本块中提供curl信息
Codeigniter删除 $ _ REQUEST
。
是在您调用 $ facebook-> getUser之前将
: $ _ GET
复制到 $ _ REQUEST
()
$ _ REQUEST + = $ _GET;
$ user = $ facebook-> getUser();
感谢这 SO回答。
The following code should return the email address of the user logged in.
<?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,
));
$user = $facebook->getUser();
print_r($user);
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'];
} catch (FacebookApiException $e) {
$user = null;
error_log($e);
print_r($e);
}
} else {
die("failed");
}
?>
Instead it returns "failed", and print_r($user) returns 0.
Really don't know what to do.
In the dashboard:
I have set up a website platform to view my app.
The jist:
The "App Domains" = www.app.com
"Site Url" = http://www.app.com/test
The site url is actual the app. I try to access the getUser
in urls such as http://www.app.com/test/fbuser
, where it returns 0 and die clause.
Did I set this up wrong?
EDIT
Curl on my localhost server
also the "Configure Command" is quite different(see below for localhost screen shot)
The remote server info mentions "curl" in this blob of text for Configure Command
Codeigniter deletes $_REQUEST
which is used by the Facebook PHP SDK to retrieve the OAuth code param.
The fix is to copy $_GET
to $_REQUEST
before your call to $facebook->getUser()
:
$_REQUEST += $_GET;
$user = $facebook->getUser();
Thanks to this SO answer.
这篇关于获取Facebook用户个人资料数据在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!