PHP Classes

File: examples/facebook_post.php

Recommend this page to a friend!
  Classes of Chun-Sheng, Li   PHP Social Network Sync   examples/facebook_post.php   Download  
File: examples/facebook_post.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Social Network Sync
Synchronize post feeds between social networks
Author: By
Last change:
Date: 1 year ago
Size: 839 bytes
 

Contents

Class file image Download
<?php
/*
* This PHP program is to post the feed via Facebook graph API.
*/

require_once __DIR__.'/../vendor/autoload.php';

$key = parse_ini_file(__DIR__.'/../api-key.ini');
$appId = $key['app_id'];
$appSecret = $key['app_secret'];
$userToken = $key['user_access_token'];
$fb = new \Facebook\Facebook([
   
'app_id' => $appId,
   
'app_secret' => $appSecret,
   
'default_graph_version' => 'v2.10',
   
'default_access_token' => $userToken,
]);

$response = $fb->post('/me/feed', [
   
'message' => 'upgrading the facebook-php-sdk from-v3.x to v5.x',
   
'link' => 'https://www.sammyk.me/upgrading-the-facebook-php-sdk-from-v3-x-to-v5',
   
$userToken,
]);

// more details about accessing the $response object
// https://developers.facebook.com/docs/php/FacebookResponse/5.0.0
$httpCode = $response->getHttpStatusCode();
echo
$httpCode;