简体   繁体   English

如何在php中获取Facebook用户详细信息?

[英]How to get the Facebook user details in php?

I am login with the facebook using the javascript sdk .Once the user is loggedin then in server side i am using this code to fetch the user details ,but it is not create the session,but in javascript it is created the session. 我使用javascript sdk登录到facebook。一旦用户登录,则在服务器端我正在使用此代码来获取用户详细信息,但这不是创建会话,而是在javascript中创建会话。

This is the my javascript code 这是我的JavaScript代码

$('body').delegate(".fblogin","click",function(){
    FB.init({appId: '', xfbml: true, cookie: true,oauth      : true,});
     FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });

once the user is loggedin then i am call the ajax function to get the friends but it is not creating the session in php side. 一旦用户登录,然后我就调用ajax函数来获取朋友,但它并没有在php端创建会话。

the PHP code is PHP代码是

if(!$this->facebook->logged_in()){
 echo '<li class="fblogin"><img src="http://naveen/app/assets/img/connect-with-facebook.png" class="ac_even"></li>';
}
else{
    $this->load->library('facebook');
    $fbfriends =  $this->facebook->call('get', 'me/friends');
    $friends=$fbfriends->data;
}

Every time it shows the fb login image. 每次显示fb登录图像。

Can any body help how to solve this problem. 任何机构都可以帮助解决该问题。 I am not very well in english.If any mistakes is there excuse me. 我的英语不太好。如果有什么错误请原谅。

Most likely it's a session issue, try switching to PHP native sessions & see if it works. 最有可能是会话问题,请尝试切换到PHP本机会话并查看其是否有效。

A native PHP session replacement library is available for download (look it up through google). 一个本地的PHP会话替换库可供下载(通过google查找)。

Hopes this would solve your issue. 希望这能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM