In diesem ausführlichem Beispiel wird gezeigt, wie mit dem Facebook SDK (Software Development Kit) per PHP ein Beitrag in eine bestehende Facebook-Seite veröffentlicht wird.
Das SDK kann per Composer installiert oder von Github heruntergeladen werden: https://github.com/facebook/php-graph-sdk
<?php include( '../include/Facebook/autoload.php' ); class fb extends \Facebook\Facebook { private $app_id = {app_id}; private $app_secret = {app_secret}; private $pageId = {page_id}; private $accessToken = {access_token}; // Ablaufdatum: Niemals public function __construct() { $config['app_id'] = $this->app_id; $config['app_secret'] = $this->app_secret; $config['default_graph_version'] = 'v2.2'; $config['cookie'] = true; parent::__construct( $config ); } /** * @param string $message * @throws \Facebook\Exceptions\FacebookSDKException * @throws Exception */ public function postMessage( $message ) { $request['message'] = $message; $this->post( '/' . $this->pageId . '/feed', $request, $this->accessToken ); } }
try { $fb = new fb(); $fb->postMessage( 'Mein erster automatischer Post' ); } catch( \Facebook\Exceptions\FacebookSDKException $e ) { echo $e->getMessage(); } catch( \Exception $e ) { echo $e->getMessage(); }