【问题标题】:Posting to Fan Page goes to wrong spot发帖到粉丝专页到错误的位置
【发布时间】:2013-01-26 03:15:58
【问题描述】:

以下内容可以正常发布到 Facebook 粉丝专页,但只能在“其他人最近在...上发布的帖子”部分下。如果我发布到正常的 FACEBOOK 页面,编码效果很好,而不是 FAN PAGE。

我已经尝试了所有我能找到的关于发布到粉丝页面的帖子。似乎没有任何效果。我的想法是我没有获得只有用户的实际页面的访问令牌。或者我没有获得具有 manage_pages 权限的返回令牌。

感谢您提供的任何帮助。

<?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;
}

?>

【问题讨论】:

    标签: php facebook facebook-page


    【解决方案1】:

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

    要以页面管理员身份发布到页面,请使用页面的适当访问令牌。你可以通过调用https://graph.facebook.com/me/accounts?access_token=YOUR_ACCESS_TOKEN找到你所有的页面和访问令牌

    【讨论】:

    • 非常感谢。你帮助我看到了显而易见的问题,而且问题往往就在你面前。我实际上并没有提取更新的(页面)令牌,并且仍在传递更新的站点令牌。现在好多了。
    • 可悲的是,它说我不能“投票”,直到我有 15 个声望。 :*(我很乐意,你又快又棒。
    • 我现在也在寻找一种更有效的方式来提取页面令牌。我为每个循环做了几个。在 $response = curl_get_file_contents($graph_url); 之后有没有更好的方法来解析和提取令牌? $decoded_response = json_decode($response);
    • 我试过 $decoded_response = json_decode($response); $new_access_token = $response['data'][0]->access_token;但我只得到不能使用字符串偏移作为数组。
    • 感谢所有帮助过的人!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多