Information about current user in facebook

有些话、适合烂在心里 提交于 2019-12-02 10:27:12

问题


I am trying to get facebook userid of the users currently logged in. I used this below piece of code ang got error "Uncaught OAuthException: An active access token must be used to query information about the current user"

require '../src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '226668060741665',
  'secret' => 'secret key',
));

$rr=$facebook->getAccessToken();

$params = array(
'access_token' => $rr,
'installed' => 'true',
'permissions' => 'read_stream,publish_stream'
);
$eded=$facebook->api("/me/", "GET", $params);

I tried to use Facebook::getLoginStatusUrl() but didnt get what it return. If i can use above function, please tell me how to get id of current logged in user and How can I use return value of Facebook::getLoginStatusUrl()

Thanks in advance


回答1:


You should use recent PHP-SDK and read documentation which shows exactly how to authenticate the user and get his details.

Exact answer you need already present in PHP-SDK examples

You may also refer to question Get ID from Facebook PHP SDK which have answer to your question too.




回答2:


Follow these steps:

  1. You generate an url: $next_url = $facebook->getLoginStatusUrl();
  2. redirect the user to this url: header('Location: '.$next_url);
  3. the user will be returned by FB with session information about the login status
  4. the SDK will parse the returned info
  5. use $facebook->getUser(); to get the access_token and userid (if logged in)

So far so good. The only problem is, this function (point 4) is broken since the transition to oAuth2.0 by Facebook API, see also this bug report: http://developers.facebook.com/bugs/295348980494364

The returned $_GET['session'] is useless in the new oAuth2.0 SDK, it was used in the old PHP-SDK v2 (current is 3.1.1).

So please let FB know that you have the same issue by adding a reproduction.

Cheers!



来源:https://stackoverflow.com/questions/8738943/information-about-current-user-in-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!