Posted inProgramming / Mysql / Mysqli / php

Automatically Post On Facebook Using PHP with Graph API

Automatically Post On Facebook Using PHP with Graph API

In this Post We Will Explain About is Automatically Post On Facebook Using PHP with Graph API With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to facebook auto post script Example

In this post we will show you Best way to implement auto post to facebook from website, hear for how to post on facebook wall using graph api with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to Auto Post on Facebook Using PHP

In this POST we Shall show you how to post step by step automatically on Social marketing like as a Facebook using PHP and Social marketing like as a Facebook Graph API.You just have to make a Social marketing like as a Facebook App and get your Access Token and need a Social marketing like as a Facebook PHP SDK to help to post on Facebook.You can also like login with facebook using PHP.

To Post On Social marketing like as a Facebook Automatically It Takes Only Three Steps:-

1.Make A Facebook App
2.Get the simple Facebook Access Token
3.create a PHP file and init methods to Post On Facebook

Step 1.make A Facebook App

Second one creating Social marketing like as a Facebook web-App you need to download here libs like as a Facebook Download PHP SDK and then it requires PHP version 5.2.0 or simple higher for PHP data call to the curl extension.and then we have to create Social marketing like as a Facebook web-App go to step by step https://developers.facebook.com/apps and then following some the instructions step by step.

Step 2.Get Social marketing like as a Facebook Access Token

To get a simple Access Token you have to set some developers accounts callback URL for the some Social marketing like as a Facebook app to get the appropriate result.And then authorize the web-app for some permissions on https://developers.facebook.com/docs/facebook-login/permissions/v2.2 as well as then get some the Access your web-Token.create sure simple renew your Facebook Token Afterall the expires 60 days because Social marketing like as a Facebook Access token will expires in about 60 days.

Step 3.Make a simple PHP file and define some methods to Post On FB MEans Facebook

We make a simple PHP file and root directory save it with a name Like as a autopost.php

connection = new Facebook($config);
 
 }
 //Devloped by Pakainfo.com
 function share($post_title, $post_URL, $share_IMGURL, $psot_desc, $access_token)
 {
  $this->connection->setAccessToken($access_token);
  $live_data["access_token"] = $access_token;
  
  if(!empty($post_title))
  {
   $live_data["message"] = $post_title;
   $live_data["name"] = $post_title;
  }
  //Devloped by Pakainfo.com
  if(!empty($post_URL))
  {
   $live_data["link"] = $post_URL;
  }
  //Devloped by Pakainfo.com
  if(!empty($share_IMGURL))
  {
   $live_data["picture"] = $share_IMGURL;
  }
  //Devloped by Pakainfo.com
  if(!empty($psot_desc))
  {
   $live_data["psot_desc"] = $psot_desc;
  }
 
  //Devloped by Pakainfo.com post to Facebook
  try 
  {
   $ret = $this->connection->api('/me/feed', 'POST', $live_data);
  }
  catch(Exception $e) 
  {
   $e->getMessage();
  }
 
  return true;
 }
 
 function getLoginUrl($live_data)
 {
  return $this->connection->getLoginUrl($live_data);
 }
 
 function getContent($url) 
 {
  $mylive_curl = curl_init();
  /*Live  Curl settings */
  curl_setopt($mylive_curl, CURLOPT_URL, $url);
  curl_setopt($mylive_curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($mylive_curl, CURLOPT_HEADER, false);
  curl_setopt( $mylive_curl, CURLOPT_CONNECTTIMEOUT, 10 );
  curl_setopt($mylive_curl, CURLOPT_SSL_VERIFYPEER, false);
 
  $response = curl_exec($mylive_curl);
  curl_close ($mylive_curl);
  return $response;
 }
 
}
?>
share($post_title, $post_URL, $share_IMGURL, $psot_desc, $access_token);
?>

And then using above source code you post will be some set your corn job posted automatically on your Social marketing like as a Facebook profile automatically share.You can also like all the get Social marketing like as a facebook like all, share total and get the comment using PHP.

Finaaly, this is how to your Post On Social marketing like as a Facebook Automatically sharing using PHP.we can customize this simple php souce code further as per your needed requirement. And please share my post feel free to share give the comments on this POST.

How to Auto Post on Facebook with PHP

To auto post on Facebook with PHP, you can use the Facebook Graph API. Here are the basic steps:

Create a Facebook app and get the app ID and app secret.
Obtain a user access token with the publish_actions permission.
Use the user access token to make a POST request to the Graph API with the message or content you want to post.

Here’s some sample code that demonstrates how to do this:

 'YOUR_APP_ID',
  'app_secret' => 'YOUR_APP_SECRET',
  'default_graph_version' => 'v3.3',
]);

// Obtain a user access token with the publish_actions permission
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();

// Use the user access token to make a POST request to the Graph API with the message you want to post
if ($accessToken) {
  try {
    $response = $fb->post('/me/feed', ['message' => 'Hello, World!'], $accessToken);
    $postId = $response->getGraphEdge()->getField('id');
    echo 'Post ID: ' . $postId;
  } catch(\Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
  } catch(\Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
  }
}

?>

Note that you’ll need to replace YOUR_APP_ID and YOUR_APP_SECRET with your actual app ID and app secret, respectively. You’ll also need to have the Facebook PHP SDK installed and configured.

Auto Post Facebook PHP Scripts

To auto post on Facebook with PHP, you can use the Facebook PHP SDK, which provides a set of functions and classes for interacting with the Facebook Graph API.

Here are the steps to auto post on Facebook with PHP:

Create a Facebook app: To post on Facebook with PHP, you need to create a Facebook app and obtain an access token. You can do this by visiting the Facebook for Developers website and following the instructions to create a new app. Once your app is created, you can generate an access token by following the instructions provided in the Facebook Developer documentation.

Install the Facebook PHP SDK: The Facebook PHP SDK can be installed using Composer, a dependency manager for PHP. To install the SDK, add the following line to your composer.json file:

"require": {
    "facebook/php-sdk-v4": "5.0.*"
}

Then run the following command in your project directory to install the SDK:

composer install

Authenticate the user: Before you can post on behalf of a user, you need to authenticate them using the Facebook SDK. You can do this by redirecting the user to the Facebook login page and requesting the necessary permissions.

Create a post: Once the user is authenticated, you can use the Facebook SDK to create a new post on their behalf. To do this, use the post method of the Facebook\Facebook class and provide the necessary parameters, such as the message and any attached media.

Here is an example code snippet to create a post:

use Facebook\Facebook;

$facebook = new Facebook([
    'app_id' => 'YOUR_APP_ID',
    'app_secret' => 'YOUR_APP_SECRET',
    'default_graph_version' => 'v3.3',
]);

$access_token = 'YOUR_ACCESS_TOKEN';

try {
    $response = $facebook->post('/me/feed', [
        'message' => 'Hello, Facebook!',
    ], $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;
}

$graphNode = $response->getGraphNode();
echo 'Post ID: ' . $graphNode['id'];

In this example, the post method is used to create a new post on behalf of the user with the message “Hello, Facebook!”. The getGraphNode method is used to retrieve the ID of the newly created post.

That’s it! With these steps, you can auto post on Facebook with PHP using the Facebook PHP SDK. Note that you should always follow the Facebook Platform Policy and ensure that you have the necessary permissions from the user to post on their behalf.
Example

I hope you have Got What is how to post into a facebook page with php using graph api And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype