为什么 Facebook PHP SDK getUser 总是返回 0?打开购物车
Why is Facebook PHP SDK getUser always returning 0? Opencart
我在 OpenCart2.1.x.
中访问 $this->fbconnect->getUser();
时得到 0
结果
下面是我正在使用的代码:
在 register
控制器中,我正在制作 URL 如下:
if(!$this->customer->isLogged()){
if(!isset($this->fbconnect)){
require_once(DIR_SYSTEM . 'facebook/facebook.php');
$this->fbconnect = new Facebook(array(
'appId' => $this->config->get('facebook_apikey'),
'secret' => $this->config->get('facebook_apisecret'),
'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL'),
'cookie' => true,
'domain'=>'abc.com'
));
}
$data['facebook_url'] = $this->fbconnect->getLoginUrl(
array(
'scope' => 'public_profile, email',
'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL')
)
);
}
和 register.tpl
中的 URL 没问题,我被重定向到 FB 登录页面进行身份验证。但是在返回我的网站时登录后,我得到 0
的 getUser()
功能。
catalog/controller/facebook/facebook.php
中的Facebook
控制器代码如下:
if(!isset($this->fbconnect)){
require_once(DIR_SYSTEM . 'facebook/facebook.php');
$this->fbconnect = new Facebook(array(
'appId' => $this->config->get('fbconnect_apikey'),
'secret' => $this->config->get('fbconnect_apisecret'),
'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL'),
));
}
$_SERVER_CLEANED = $_SERVER;
$_SERVER = $this->clean_decode($_SERVER);
echo $fbuser = $this->fbconnect->getUser(); **0**
完整代码可以在这里找到:: Click Here
我的应用设置是:
此处:: abc.com
表示我的实际网站 URL 将被替换为此处。
Please do not mark this question as DUPLICATE because i have already searched on SO and everywhere and nothing is working here for me. So, please try to give the solution and that is i am posting question after searching for more than 1 day.
试试这个 ;)
替换
echo $fbuser = $this->fbconnect->getUser();
和
try {
// Returns a `Facebook\FacebookResponse` object
$response = $this->fbconnect->get('/me?fields=id,name', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Id: ' . $user['id'];
echo 'Name: ' . $user['name'];
我在 OpenCart2.1.x.
中访问$this->fbconnect->getUser();
时得到 0
结果
下面是我正在使用的代码:
在
register
控制器中,我正在制作 URL 如下:if(!$this->customer->isLogged()){ if(!isset($this->fbconnect)){ require_once(DIR_SYSTEM . 'facebook/facebook.php'); $this->fbconnect = new Facebook(array( 'appId' => $this->config->get('facebook_apikey'), 'secret' => $this->config->get('facebook_apisecret'), 'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL'), 'cookie' => true, 'domain'=>'abc.com' )); } $data['facebook_url'] = $this->fbconnect->getLoginUrl( array( 'scope' => 'public_profile, email', 'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL') ) ); }
和 register.tpl
中的 URL 没问题,我被重定向到 FB 登录页面进行身份验证。但是在返回我的网站时登录后,我得到 0
的 getUser()
功能。
catalog/controller/facebook/facebook.php
中的Facebook
控制器代码如下:if(!isset($this->fbconnect)){ require_once(DIR_SYSTEM . 'facebook/facebook.php'); $this->fbconnect = new Facebook(array( 'appId' => $this->config->get('fbconnect_apikey'), 'secret' => $this->config->get('fbconnect_apisecret'), 'redirect_uri' => $this->url->link('facebook/facebook', '', 'SSL'), )); } $_SERVER_CLEANED = $_SERVER; $_SERVER = $this->clean_decode($_SERVER); echo $fbuser = $this->fbconnect->getUser(); **0**
完整代码可以在这里找到:: Click Here
我的应用设置是:
此处:: abc.com
表示我的实际网站 URL 将被替换为此处。
Please do not mark this question as DUPLICATE because i have already searched on SO and everywhere and nothing is working here for me. So, please try to give the solution and that is i am posting question after searching for more than 1 day.
试试这个 ;)
替换
echo $fbuser = $this->fbconnect->getUser();
和
try {
// Returns a `Facebook\FacebookResponse` object
$response = $this->fbconnect->get('/me?fields=id,name', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Id: ' . $user['id'];
echo 'Name: ' . $user['name'];