Created
November 17, 2015 08:27
-
-
Save thanhhh/189c206951868bc22e07 to your computer and use it in GitHub Desktop.
Auto post to Facebook page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Facebook\Authentication\AccessToken; | |
use Facebook\FacebookApp; | |
use Facebook\FacebookRequest; | |
session_start(); | |
$app_id = '{APP ID}'; | |
$app_secret = '{APP SECRET}'; | |
$app = new FacebookApp($app_id, $app_secret); | |
$fb = new Facebook\Facebook(array( | |
'app_id' => $app_id, | |
'app_secret' => $app_secret, | |
'default_graph_version' => 'v2.5', | |
)); | |
//Page access token has been got from get_page_access_token.php | |
$access_token = '{PAGE ACCESS TOKEN}'; | |
$page_id = '{PAGE ID}'; | |
$post_data = array( | |
'message' => '{Your message data here}' | |
); | |
$request = new FacebookRequest($app, $access_token, 'POST', '/' . $page_id . '/feed', $post_data); | |
// Send the request to Graph | |
try { | |
$response = $fb->getClient()->sendRequest($request); | |
$graphNode = $response->getGraphNode(); | |
echo 'Post ID: ' . $graphNode['id']; | |
} catch(Facebook\Exceptions\FacebookResponseException $e) { | |
// When Graph returns an error | |
echo 'Graph returned an error: ' . $e->getMessage(); | |
exit; | |
} catch(Facebook\Exceptions\FacebookSDKException $e) { | |
// When validation fails or other local issues | |
echo 'Facebook SDK returned an error: ' . $e->getMessage(); | |
exit; | |
} |
is this working until now?
any updates?
@ProjectSeve
You should check https://github.com/facebook/facebook-php-business-sdk/tree/master/examples for the latest Facebook SDK version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question: Is it possible to use this to post to the Facebook Marketplace?