Create PHP file in your local server
Download Facebook PHP SDK (v.3.2.2 at the time of writing this article) from Github at You may use any library available (in PHP section) of https://github.com/facebook/facebook-php-sdk.
Get the access token steps
Put the following code in the php file in your local server
<?php
require_once
(
"/path/to/facebook_php_sdk/facebook.php"
);
// set the right path
$config
=
array
();
$config
[
'appId'
] =
'167252680143474'
;
$config
[
'secret'
] =
'29d8d368420dc1e81198fce224ac71c9'
;
$config
[
'fileUpload'
] = false;
// optional
$fb
=
new
Facebook(
$config
);
$params
=
array
(
// this is the main access token (facebook profile)
"access_token"
=>
"CAACYHYyWcnIBAJ1LwRLTERQNXJ4qRCqoTf2pgs1V2AiZCOreWAH0bY2UKaoyD3elfcEZAZAs6fZAEYPAZC5OlU6ZCg8Org32D13LiencxZA0PsNzkQPPuZCiZAukgMnqLXM0F2ZBlYZAnZB08qVwOo6DgiCJSlkoZCb9VVs0ARsleZBcduzTQKZBvIcvjLZBXXr5ye8R4FcZD"
,
"message"
=>
"Here is a blog post about auto posting on Facebook using PHP #php #facebook"
,
"name"
=>
"How to Auto Post on Facebook with PHP"
,
"caption"
=>
"www.pontikis.net"
,
"description"
=>
"Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
);
try
{
$ret
=
$fb
->api(
'/me/feed'
,
'POST'
,
$params
);
echo
'Successfully posted to Facebook Personal Profile'
;
}
catch
(Exception
$e
) {
echo
$e
->getMessage();
}
?>
Download Facebook PHP SDK (v.3.2.2 at the time of writing this article) from Github at You may use any library available (in PHP section) of https://github.com/facebook/facebook-php-sdk.
Get the access token steps
Put the following code in the php file in your local server
<?php
print_r(
$_GET
);
?>
On your browser, give the following url, where client_id is App ID
and redirect_uri
is the URL defined as Canvas URL
After getting the code value, give the
following url, where client_id
is App ID and redirect_uri
is the URL defined as Canvas URL, client_secret is App Secret and
code is the
code
got.Finally you can post your message to Facebook