简体   繁体   中英

Facebook PHP SDK 5.0 - Posting to group

I have been stumped for a while now. I'm attempting to write myself a small app to automatically post to a number of groups that I am members of in FB. I'm a PHP novice, but this is about my strongest skill set for what FB allows in terms of access that I can tell. So far, I CAN post to my own wall no problem but once I try and post to my own FB testing group I'm stumped. Here is my code so far...

<?php
require_once __DIR__ . '/vendor/autoload.php';    
require 'src/config.php';
require 'src/facebook.php';

$fb = new Facebook\Facebook([
  'app_id' => $config['App_ID'],
  'app_secret' => $config['App_Secret'],
  'default_graph_version' => 'v2.8',
  ]);

$linkData = [
  'link' => 'http://www.example.com',
  'message' => 'Test post to my feed.',
  ];

try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post('/{group_id}/feed', $linkData, $config['Access_Token']);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
?>

Currently the error that this is generating is: Graph returned an error: (#200) Insufficient permission to post to target on behalf of the viewer

I have made the app Public and generated the access token with manage_pages and publish_pages. Unfortunately I'm out of ideas as of this point. Any help would be greatly appreciated. Thanks in advance.

OK. I figured out my problem at this point. It was that I had to go into the App Settings in my FB user account and change my App from "Only Me" to Public. Once I did that I was able to post to my groups. Next will be to figure out how to post into the proper fields for a "Sell Something" type of post and then to test it in groups that I'm not an admin of.

I figure it has to be possible to post into non-admin groups since there are a number of services out there for FB auto-posting and they have to get around it somehow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM