Thomas Kekeisen
Thomas Kekeisen

Reputation: 4406

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 "normal" 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!

Upvotes: 2

Views: 1122

Answers (3)

Adi_aks
Adi_aks

Reputation: 511

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

Upvotes: 0

DMCS
DMCS

Reputation: 31860

$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);

Upvotes: 1

Anastasia
Anastasia

Reputation: 11

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);

Upvotes: 1

Related Questions