我是Facebook SDK for PHP的新手。我在这里有一个非常基本的问题(这个答案没有帮助):我目前登录到我的 Facebook 个人资料,但是getUser()
没有返回任何内容。为什么?
require_once("vendor/facebook-php-sdk/src/facebook.php");
class Controller_Test extends Controller {
public function action_me()
{
$config = array();
$config['appId'] = 'dfjq454...';
$config['secret'] = 'adfw424...';
$config['fileUpload'] = false;
$facebook = new Facebook($config);
$user = $facebook->getUser();
// Returns '0'
echo "Me: ".$user;
// ...
编辑1:
我尝试在 bootstrap.php 中取消注释这一行,但它不起作用'auth' => MODPATH.'auth', // Basic authentication
编辑 2: 当我运行以下代码时
$user_profile = $facebook->api('/me');
echo "My Profile: ".$user_profile;
我收到这个错误
必须使用活动访问令牌来查询有关当前用户的信息。
编辑 3
FacebookApiException [ 0 ]: An active access token must be used to query information about the current user.
DOCROOT\vendor\facebook-php-sdk\src\base_facebook.php [ 1272 ]
1267 *
1268 * @param $result array A record storing the error message returned
1269 * by a failed API call.
1270 */
1271 protected function throwAPIException($result) {
1272 $e = new FacebookApiException($result);
1273 switch ($e->getType()) {
1274 // OAuth 2.0 Draft 00 style
1275 case 'OAuthException':
1276 // OAuth 2.0 Draft 10 style
1277 case 'invalid_token':
DOCROOT\vendor\facebook-php-sdk\src\base_facebook.php [ 881 ] » BaseFacebook->throwAPIException(arguments)
{PHP internal call} » BaseFacebook->_graph(arguments)
DOCROOT\vendor\facebook-php-sdk\src\base_facebook.php [ 654 ] » call_user_func_array(arguments)
APPPATH\classes\Controller\test.php [ 17 ] » BaseFacebook->api(arguments)
SYSPATH\classes\Kohana\Controller.php [ 84 ] » Controller_Test->action_me()
{PHP internal call} » Kohana_Controller->execute()
SYSPATH\classes\Kohana\Request\Client\Internal.php [ 97 ] » ReflectionMethod->invoke(arguments)
SYSPATH\classes\Kohana\Request\Client.php [ 114 ] » Kohana_Request_Client_Internal->execute_request(arguments)
SYSPATH\classes\Kohana\Request.php [ 986 ] » Kohana_Request_Client->execute(arguments)
DOCROOT\index.php [ 118 ] » Kohana_Request->execute()