在php中获取Facebook用户个人资料数据 [英] Get Facebook user profile data in php
问题描述
以下代码应该返回登录用户的电子邮件地址。
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");
}
?>
而是返回failed,print_r($ user)返回0。
Instead it returns "failed", and print_r($user) returns 0.
真的不知道该怎么办。
在仪表板中:
我有设置一个网站平台来查看我的应用程序。
I have set up a website platform to view my app.
jist:
App Domains= www.app.com
网站网址= http://www.app.com/test
该网站是实际的应用程序。我尝试访问url中的 getUser
,例如 http://www.app.com/test/fbuser
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?
编辑
我的本地服务器上的卷曲
Curl on my localhost server
还有配置命令是完全不同的(请参见下面的本地主屏幕截图)
also the "Configure Command" is quite different(see below for localhost screen shot)
远程服务器信息在配置命令的这个文本块中提到curl
The remote server info mentions "curl" in this blob of text for Configure Command
推荐答案
Codeigniter删除Facebook PHP SDK使用的 $ _ REQUEST
来检索OAuth代码参数。
Codeigniter deletes $_REQUEST
which is used by the Facebook PHP SDK to retrieve the OAuth code param.
修复在您致电 $ facebook-> getUser之前,将
: $ _ GET
复制到 $ _ REQUEST
()
The fix is to copy $_GET
to $_REQUEST
before your call to $facebook->getUser()
:
$_REQUEST += $_GET;
$user = $facebook->getUser();
感谢这个的答案。
这篇关于在php中获取Facebook用户个人资料数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!