好的,所以我正在尝试使用 ajax 发布到 facebook。问题是我没有登录。这是正在请求的页面。config 仅包含我的 facebook 应用程序身份验证详细信息。我想我只是不明白在尝试使用 ajax 执行此请求时,我尝试过的所有操作都返回 0(无用户)。
<?php
require_once 'includes/config.php';
//Including facebook php sdk file
require_once 'includes/php-sdk/facebook.php';
//Creating our application instance
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => true
));
//Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$access_token = $facebook->getAccessToken();
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
//In order to post to the page later on we need to generate an Access Token for that page, to do this we get me-accounts in the following api call
$accounts = $facebook->api('/me/accounts');
}