开发者

Add a wall post to a page or application wall as page or application with facebook graph API

I wan't to create a new wall post on a appliaction page or a "norma开发者_如何学Gol" page with the facebook graph API. Is there a way to "post as page"? With the old REST-API it worked like this:

$facebook->api_client->stream_publish($message, NULL, $links, $targetPageId, $asPageId);

So, if I passed equal IDs for $targetPageId and $asPageId I was able to post a "real" wall post not caused by my own facebook account.

Thanks!


$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
    if($page["id"] == $page_id) {
        $page_access_token = $page["access_token"];
        break;
    }
}
$args = array(
    'access_token'  => $page_access_token,
    'message'       => "I'm posting as a Page!"
);
$post_id = $facebook->api("/$page_id/feed","post",$args);


To publish as Page you need to add manage_pages permission first of all (and get the tokens). Next use something like this:

    $url = 'https://api.facebook.com/method/stream.publish?message=TEST&target_id=PAGEID&uid=PAGEID&access_token=YOUR_TOKEN';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_URL, $url);

    $result = curl_exec($ch);
    curl_close($ch);


Set the value of targetpageid=null and check the output...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜