Php 发帖到粉丝页面的位置出错

Php 发帖到粉丝页面的位置出错,php,facebook,facebook-page,Php,Facebook,Facebook Page,以下内容可以很好地发布到Facebook粉丝页面,但只能在“他人最近在……上发布的帖子”部分下发布。如果我在正常的FACEBOOK页面上发帖,而不是在粉丝页面上发帖,那么代码就可以很好地工作 我已经尝试了所有我能找到的关于发布到粉丝页面的帖子。似乎什么都不管用。我的想法是,我不会只为用户获取实际页面的访问令牌。或者我没有获得具有“管理页面”权限的返回令牌 谢谢你能提供的帮助 <?php $app_id = xxxxxxxxxx; // APP ID $app_secret = xxxxx

以下内容可以很好地发布到Facebook粉丝页面,但只能在“他人最近在……上发布的帖子”部分下发布。如果我在正常的FACEBOOK页面上发帖,而不是在粉丝页面上发帖,那么代码就可以很好地工作

我已经尝试了所有我能找到的关于发布到粉丝页面的帖子。似乎什么都不管用。我的想法是,我不会只为用户获取实际页面的访问令牌。或者我没有获得具有“管理页面”权限的返回令牌

谢谢你能提供的帮助

<?php 
$app_id = xxxxxxxxxx; // APP ID
$app_secret = xxxxxxxxxxxx;
$my_url = "http : // www . afakewebsitefordemoonly.com/thispageURL.php";
$fb_id = xxxxxxxxxxx; // ACTUAL FAN PAGE NUMBER


// known valid access token stored in a database
$access_token = MANUAL_ACCESS_TOKEN; // GOT MANUAL ACCESS TOKEN FROM API Explorer - expires in about 90 minutes but good enough to request a new token. THE original TOKEN HAS manage_pages and publish_stream permissions.

$code = $_REQUEST["code"];

// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.

if (isset($code)) {

    $token_url="https : // graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&client_secret=" . $app_secret
    . "&code=" . $code . "&display=popup";
    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);
    $access_token = $params['access_token'];
}


// Attempt to query the graph:
$graph_url = "https : //graph.facebook.com/me?" . "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);

//Check for errors
if ($decoded_response->error) {
    // check to see if this is an oAuth error:
    if ($decoded_response->error->type== "OAuthException") {
        // Retrieving a valid access token.
        $dialog_url= "https : // www . facebook.com/dialog/oauth?"
        . "client_id=" . $app_id
        . "&redirect_uri=" . urlencode($my_url);
        echo("<script> top.location.href='" . $dialog_url
        . "'</script>");
    }
    else {
        echo "other error has happened";
    }
}
else {
    // success
    //echo("success" . $decoded_response->name);
    //echo($access_token);
    /******************************/
    //$data['from'] = $fb_id;
    //$data['picture'] = "http :// www. URL_TO_PHOTO.jpg";
    $data['link'] = "http  :// www .fakewebsitefortesting.com/"; // static link I want to put on post on my site.
    $data['message'] = "Message here.";
    $data['subject'] = 'Some Subject';
    $data['title'] = 'Fancy Title here';
    $data['description'] = "Description is more info here.";
    $data['access_token'] = $access_token;

    $post_url = 'https : // graph.facebook.com/'. $fb_id . '/feed';

    echo "Post URL: ". $post_url . "<br />";
    echo "Data: " . $data . "<br />";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $post_url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $return = curl_exec($ch);
    curl_close($ch);
    echo "Return: ". $return . "<br />";
    /******************************/

}

// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes.  In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL) {
    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_URL, $URL);
    $contents = curl_exec($c);
    $err  = curl_getinfo($c,CURLINFO_HTTP_CODE);
    curl_close($c);
    if ($contents) return $contents;
    else return FALSE;
}

?>

您没有使用页面的访问令牌,因此Facebook将您视为普通用户(而不是页面管理员),并将您的帖子添加到“他人最近发布的帖子”中


要以页面管理员的身份发布到页面,请为页面使用适当的访问令牌。通过对

进行api调用,您可以找到所有页面和访问令牌。非常感谢。你帮助我看到了显而易见的问题,而问题往往就在你面前。实际上,我并没有提取更新的(页面)令牌,而是在传递更新的站点令牌。现在一切都好了。可悲的是,它说我只有15岁才能“投票”*(我很乐意,你很快就完成了。我现在也在寻找一种更有效的方法来提取页面令牌。我已经为每个循环做了几次。在$response=curl\u get\u file\u contents($graph\u url);$decoded\u response=json\u decode($response)之后,有没有更好的方法来解析和提取令牌呢($response);$new_access_token=$response['data'][0]->access_token;但我只能得到不能将字符串偏移量用作数组的结果。感谢所有帮助过我的人!