facebook social marketing

Add batch/multiple posts to Facebook Page – Graph API

facebook graph API batch request usage

If you have or managing any facebook page, chances are you might be using faebook’s graph API. It comes with lots of flavors of languages like Java, PHP, Javascript.

Ok you know about that, this post is not about that. If you want to see how to make a post to facebook through graph API, look at this post https://gullele.com/using-facebook-api-post-articles-php/

This post is about making multiple posts to Facebook page.

Why would I need batch requests

Imagine you have 20 blog articles you want to post to facebook. If you are not using batch, then it means you are sending 20 post requests to facebook. And as you can imaging it is easy to hit the limit easily. Facebook will stop you from bombarding their site.

When you are using batch, you have only one request, holding all 20 posts. Yup, that is it. One request vs 20. Now you know why you have to use that.

How to send multiple blog posts or other posts to Facebook page at once

If you follow the above link I referenced, you will have an idea on how single post is doing. I will just continue on that example class and will add just one more method to handle batch request.

The main idea is, each blog or whatever post has to be an object of Request. And you will send all those requests wrapped in one and send it.


	/**
	 * Send batch request to FB than a single one
	 * @param $post_data
	 */
	private function batchPost(array $post_data, $token)
	{
		/*
		 * In the case of the batch request, each has to be an object of request. And all those can be 
		 * send as one big request.
		 */
		$batch_response = [];
		$requests = [];
		foreach ($post_data as $id => $data) {
			$requests[$id] = $this->facebook->request('POST', '/me/feed', $data);
		}

		$batch_response = $this->facebook->sendBatchRequest($requests, $token);

		return $batch_response;
	}

In the above example, the method will be accepting $post_data as a parameter. If a post example is considered, a single $data will look like


$data = [
			'link' => "https://gullele.com/link-goes-here",
			'message'=>"how to make batch request in facebook api",
			'title'=>"Making Multiple Requests in Facebook",
			'description' => 'In this article I will show you how you can make multiple blog posts to Facebook page with one single request.',
		];

Then the line with $this->facebook->request will create a request object and add it as part of request array. Also mind the $id, each should have unique key in the $request array.

Then Facebook will send you back the response with post id and other lots of information that you might want to keep it for later reference like to get metrics on the post – how many likes, impressions, shares.. which will help you to improve in the long run.

Let me know if you have any questions or other methods.

Using Facebook API to post articles from PHP

How to automatically post to facebook page using PHP

This one is a bit detailed tutorial that is assumed for a novice php programmer who is new to Facebook API

Step 1.
Create a developer account from developer.facebook.com. All you need is your facebook account and you can get a developer account from it.

Step 2.
Create a Facebook page. From your Facebook page, on the top right corner, click on the dropdown menu and hit on create page. Select the type of the page you would like to create and then you have it.

Now what you want to do is, to create an auto post to the facebook page you just created from PHP. Lets say you run a blog or product page and you want to post whenever there is new stuff to be posted to the facebook page automatically.
Continue reading Using Facebook API to post articles from PHP

facebook social marketing

Post to Facebook From app – Using PHP

Post to Facebook programatically

You can post whatever you like from PHP to your or company’s page. Facebook has provided an SDK that makes life easier to post to the Facebook page.

This is ideal if you want to post to facebook, from cron job especially. Or on some event like right after the post in wordpress.

First thing first, you need to have a developer account on Facebook and you can do that easily and free on https://developers.facebook.com

Then you need to create an app. A single page or something like that would work. You will see how to create one when you are setting up your account for developer.

Once you have that, on the left menu, you will see dashboard. This contains important information about the app you will use to interact from your code.
Continue reading Post to Facebook From app – Using PHP

facebook social marketing

Hooking Facebook App to Existing FB Business Manager

Working on Facebook marketing reporting which require setting up a Facebook App and hooking it to existing Business manager and it looks there is no direct instruction that I found so here you go…

First thing first, you would need a developer account from https://developers.facebook.com/ – go and get it, it is free.

Then Go ahead and create a Facebook App there – a minimum you need is a facebook page and thats it.
Then from the dashboard you will get the app_id and secret. This is very important for you to keep it as secret as well. From this, you will get yet another important key called Access Token.

Now you have a Facebook App that you will use it to acquire a lot of information for the business manager you have. You can get lots of User related data, analytics, sales, spending and more..

Now head to https://business.facebook.com/ and select your business manager if you have more than one.
On the left of the menu, you will see Claim Assets and from there select App
You will be asked to insert App Id and it will be a matter of following the instruction after that.
Now you have integrated your app to the existing business manager. Which means, your app now has an access to the data under your business manager through different APIs.

EnJoy