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
<?php require_once("FacebookSDK/facebook.php"); class FacebookApi { //Devloped by Pakainfo.com init all the php var var $consumer; /* Live token*/ var $token; var $method; /* Live status know*/ var $http_status; var $last_api_call; /* Live callback*/ var $callback; var $connection; var $access_token; //Devloped by Pakainfo.com function __construct($data) { $config = array(); $config['appId'] = $data['consumer_key']; $config['secret'] = $data['consumer_secret']; $this->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; } } ?>
<?php $access_token = "LIVE YOUR ACCESS TOKEN"; $facebookData = array(); $facebookData['consumer_key'] = "Put_YOUR_KEY"; $facebookData['consumer_secret'] = Put_YOUR_SECREATE_KEY; $post_title = "Auto Post On Facebook Using PHP"; $post_URL = "https://www.pakainfo.com/"; $share_IMGURL = "https://www.pakainfo.com/live.jpg"; $psot_desc = "We are Web Technology Experts and Team who provide you very Important information on Web Development information,Examples and Demo, Interview Questions and Answers, live project problem solution and their solution and online free tutorials β Pakainfo.com."; $facebook = new FacebookApi($facebookData); $facebook->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:
<?php require_once __DIR__ . '/vendor/autoload.php'; // Include the Facebook PHP SDK $fb = new \Facebook\Facebook([ 'app_id' => '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.
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.