0

I try to add post on facebook page and get error I use this code to crate simple post to fasebook

<?php
$page_access_token = $token;
$page_id = $pageid;

$data['picture'] = "http://www.example.com/image.jpg";
$data['link'] = "http://www.example.com/";
$data['message'] = "Your message";
$data['caption'] = "Caption";
$data['description'] = "Description";

$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';


$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);
print_r($return);
curl_close($ch);
?>

Then i get this error

{
  "error": {
    "message": "(#200) If posting to a group, requires app being installed in the group, and \\\n either publish_to_groups permission with user token, or both pages_read_engagement \\\n and pages_manage_posts permission with page token; If posting to a page, \\\n requires both pages_read_engagement and pages_manage_posts as an admin with \\\n sufficient administrative permission",
    "type": "OAuthException",
    "code": 200,
    "fbtrace_id": "AWUp2P-dJhVZIxNWThYO91V"
  }
}

I try to find solution on google but still not find the problem someone know what i am doing wrong?

meewog
  • 1,690
  • 1
  • 22
  • 26
  • Two most likely causes: Your page access token either does not include the mentioned required permissions, or it is not actually a page token to begin with. – CBroe Aug 11 '20 at 09:21
  • (And you can only specify picture, caption and description for domains your page has claimed “onwership” for, otherwise these parameters will be ignored, and the value from the OG meta tags of the shared URL will be used.) – CBroe Aug 11 '20 at 09:23
  • how i can find this $page_access_token and $page_id i try this token http://prntscr.com/txro0c and page-id i take from page -> about ->page id – tsohar zigdon Aug 11 '20 at 12:57
  • Select “page” in the “user or page” field … – CBroe Aug 11 '20 at 13:15
  • Thanks very much i find solution here http://prntscr.com/ty6ppp but i wants the token will not expire? – tsohar zigdon Aug 12 '20 at 06:36

1 Answers1

0

The code is correct $page_access_token = $token; $page_id = $pageid; to find this need to use

Finally, after a lot of tests, it worked, without the PHP SDK. This is the step by step guide:

  1. Get permissions and the page token

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left.

Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.

You may be asked in this step to grant permissions to your app to access to your Facebook account, accept.

Next, click at the end of the text field next to the "GET" drop down, and replace the numbers for: me/accounts, and click in the blue button next to this text field.

You'll get the tokens for all your pages, including your app page. Find your page name in the list, will look like this: "name": "Your page name"

When you located your page, copy the access token for the page (will be really long), that can look like this: "access_token": "XXXXXXXX". Also copy the id of the page: "id": "XXXXX".

That's all for this step, we can start coding now. Simple example to post to a Facebook fan page via PHP? and this if u wants token will not expire Never Expiring Facebook Page Access Token

Thanks for helping