<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Graph API Archives -</title>
	<atom:link href="https://datamatric.com/blog/tag/graph-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://datamatric.com/blog/tag/graph-api/</link>
	<description>DataMatric Blog - Boost Sales &#38; Business Management</description>
	<lastBuildDate>Tue, 17 Dec 2024 04:58:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>How to auto publish post in Facebook page &#8211; using Graph API</title>
		<link>https://datamatric.com/blog/how-to-auto-post-in-facebook-page-using-graph-api/</link>
					<comments>https://datamatric.com/blog/how-to-auto-post-in-facebook-page-using-graph-api/#comments</comments>
		
		<dc:creator><![CDATA[Crafty]]></dc:creator>
		<pubDate>Fri, 19 Apr 2024 19:50:09 +0000</pubDate>
				<category><![CDATA[Digital Marketing]]></category>
		<category><![CDATA[Facebook Marketing]]></category>
		<category><![CDATA[API Key]]></category>
		<category><![CDATA[auto post in Facebook page]]></category>
		<category><![CDATA[data matric]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[Facebook Developer Console]]></category>
		<category><![CDATA[Graph API]]></category>
		<guid isPermaLink="false">https://datamatric.com/blog/?p=35</guid>

					<description><![CDATA[<p>Are you looking for how to auto publish post in Facebook Page-using Graph API? You can get all the instruction on how to auto-publish posts [&#8230;]</p>
<p>The post <a href="https://datamatric.com/blog/how-to-auto-post-in-facebook-page-using-graph-api/">How to auto publish post in Facebook page &#8211; using Graph API</a> appeared first on <a href="https://datamatric.com/blog"></a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Are you looking for how to auto publish post in Facebook Page-using Graph API? You can get all the instruction on how to auto-publish posts on the Facebook page &#8211; using Graph API by reading this blog. The Expertise of <a href="https://datamatric.com/">Data Matric</a> help you to publish auto-posts on your Facebook Page.</p>



<h2 class="wp-block-heading">What are we going to achieve ?</h2>



<p>Suppose, you have a Facebook page. But you don&#8217;t have enough time to publish thousands of posts. You want auto post in Facebook page? Yes, you can automate the process completely. A software system or bot will be posting frequently on your behalf. You just need to set which contents (Text, Image, Video etc.) you want to post automatically.</p>



<ul class="wp-block-list">
<li>You can set the interval between postings. You can post something every hour, every 2 hours or every 12 hours etc. Or even every minute, though it&#8217;s not a good idea at all.</li>
</ul>



<ul class="wp-block-list">
<li>Does it cost money ? Not a single penny !</li>
</ul>



<ul class="wp-block-list">
<li>Anyway I will show you an example. I am giving you a <a href="https://www.facebook.com/122102557712000696" target="_blank" rel="noreferrer noopener">Facebook page link</a> which manage all their posts with the help of Facebook Graph API.</li>
</ul>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6877f2068cc4f&quot;}" data-wp-interactive="core/image" class="wp-block-image size-full wp-lightbox-container"><img fetchpriority="high" decoding="async" width="694" height="739" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on-async--click="actions.showLightbox" data-wp-on-async--load="callbacks.setButtonStyles" data-wp-on-async-window--resize="callbacks.setButtonStyles" src="https://datamatric.com/blog/wp-content/uploads/2024/04/jovoc-image-acclaim.png" alt="facebook page auto post example" class="wp-image-84" srcset="https://datamatric.com/blog/wp-content/uploads/2024/04/jovoc-image-acclaim.png 694w, https://datamatric.com/blog/wp-content/uploads/2024/04/jovoc-image-acclaim-282x300.png 282w" sizes="(max-width: 694px) 100vw, 694px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="Enlarge"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on-async--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>Not only auto posting from predefined content, but also you can query database or scrape web, prepare data and then post in Facebook automatically. That will be more complex, but easy if you are an experienced developer.  The marked content in the above emails has been queried from MySQL database, then processed and then posted in Facebook page automatically</p>



<h2 class="wp-block-heading" id="create_app">Initial setup</h2>



<ul class="wp-block-list">
<li>At first, you have to create a Facebook app from <a href="https://developers.facebook.com/apps/creation/" target="_blank" rel="noreferrer noopener">Facebook developer console</a> . For your convenience I will give you a YouTube tutorial which shows every step comprehensively.</li>
</ul>



<ul class="wp-block-list">
<li>After you finish this video I will provide you some code sample that works seamlessly.</li>
</ul>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Facebook API Tutorial: Graph API, Access Token and Developer Documentation Explained" width="640" height="360" src="https://www.youtube.com/embed/to4uTxSNo6Q?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading">API Key</h2>



<p>From the above video you have got the  API key, please save the API key with proper security. Then we will send a Http POST request to the API URL using CURL. Notice the API URL structure:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="$url = &quot;https://graph.facebook.com/$pageId/photos?url=$imagePath&amp;caption=$content&amp;access_token=$accessToken&quot;;" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F8F8F2">$url </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">https://graph.facebook.com/</span><span style="color: #F8F8F2">$pageId</span><span style="color: #F1FA8C">/photos?url=</span><span style="color: #F8F8F2">$imagePath</span><span style="color: #F1FA8C">&amp;caption=</span><span style="color: #F8F8F2">$content</span><span style="color: #F1FA8C">&amp;access_token=</span><span style="color: #F8F8F2">$accessToken</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">;</span></span></code></pre></div>



<p>To call this API, you need the Facebook page ID. Now question is how you can find the page ID ?</p>



<h2 class="wp-block-heading">How to get / find Facebook page ID ?</h2>



<ol class="wp-block-list">
<li>Go to your Facebook page </li>



<li> Press <strong>CTRL + U</strong> . This will open page source code.</li>



<li>Press <strong>CTRL + F</strong> and write <strong><em>delegate_page_id</em></strong>  . Then you will find an object which looks like </li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="&quot;user&quot;:{&quot;id&quot;:&quot;61550xxxx580&quot;,&quot;delegate_page_id&quot;:&quot;12210xxxx71200696&quot;}" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">user</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">:{</span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">id</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">:</span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">61550xxxx580</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">,</span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">delegate_page_id</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">:</span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">12210xxxx71200696</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">}</span></span></code></pre></div>



<p> Note that searching for <strong><em>delegate_page_id</em></strong>   we&#8217;ll find multiple match. Search for next match until you find an object like this. For your convenience I am also attaching a screenshot :<br></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6877f2068d99d&quot;}" data-wp-interactive="core/image" class="wp-block-image size-full wp-lightbox-container"><img decoding="async" width="629" height="121" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on-async--click="actions.showLightbox" data-wp-on-async--load="callbacks.setButtonStyles" data-wp-on-async-window--resize="callbacks.setButtonStyles" src="https://datamatric.com/blog/wp-content/uploads/2024/04/Capture.png" alt="how to find facebook page ID" class="wp-image-128" srcset="https://datamatric.com/blog/wp-content/uploads/2024/04/Capture.png 629w, https://datamatric.com/blog/wp-content/uploads/2024/04/Capture-300x58.png 300w" sizes="(max-width: 629px) 100vw, 629px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="Enlarge"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on-async--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h2 class="wp-block-heading">Auto posting code</h2>



<p>Now read the code with attention:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="&lt;?php

/**
 * Post to Facebook Page using Graph API.
 *
 * @param string $pageId The ID of the Facebook page to post to.
 * @param string $accessToken The access token with the necessary permissions.
 * @param string $content The message or caption to post.
 * @param string $imagePath The URL of the image to post (optional).
 *
 * @return mixed The API response as a JSON-decoded object or array.
 */
function postToFacebookPage($pageId, $accessToken, $content, $imagePath = null){
    // Encode content as URL-safe string
    $content = urlencode($content);

    // Determine the endpoint and payload
    if ($imagePath) {
        // If an image path is provided, post as a photo
        $url = &quot;https://graph.facebook.com/$pageId/photos?url=$imagePath&amp;caption=$content&amp;access_token=$accessToken&quot;;
    } else {
        // Otherwise, post as a regular feed message
        $url = &quot;https://graph.facebook.com/$pageId/feed?message=$content&amp;access_token=$accessToken&quot;;
    }

    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);

    // Execute cURL session and capture the response
    $response = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        throw new Exception('cURL Error: ' . curl_error($ch));
    }

    // Close cURL session
    curl_close($ch);

    // Decode JSON response and return it
    return json_decode($response, true);
}
" style="color:#F8F8F2;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dracula" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #FF79C6">&lt;?</span><span style="color: #BD93F9">php</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6272A4">/**</span></span>
<span class="line"><span style="color: #6272A4"> * Post to Facebook Page using Graph API.</span></span>
<span class="line"><span style="color: #6272A4"> *</span></span>
<span class="line"><span style="color: #6272A4"> * </span><span style="color: #FF79C6">@param</span><span style="color: #6272A4"> </span><span style="color: #FF79C6">string</span><span style="color: #6272A4"> $pageId The ID of the Facebook page to post to.</span></span>
<span class="line"><span style="color: #6272A4"> * </span><span style="color: #FF79C6">@param</span><span style="color: #6272A4"> </span><span style="color: #FF79C6">string</span><span style="color: #6272A4"> $accessToken The access token with the necessary permissions.</span></span>
<span class="line"><span style="color: #6272A4"> * </span><span style="color: #FF79C6">@param</span><span style="color: #6272A4"> </span><span style="color: #FF79C6">string</span><span style="color: #6272A4"> $content The message or caption to post.</span></span>
<span class="line"><span style="color: #6272A4"> * </span><span style="color: #FF79C6">@param</span><span style="color: #6272A4"> </span><span style="color: #FF79C6">string</span><span style="color: #6272A4"> $imagePath The URL of the image to post (optional).</span></span>
<span class="line"><span style="color: #6272A4"> *</span></span>
<span class="line"><span style="color: #6272A4"> * </span><span style="color: #FF79C6">@return</span><span style="color: #6272A4"> </span><span style="color: #FF79C6">mixed</span><span style="color: #6272A4"> The API response as a JSON-decoded object or array.</span></span>
<span class="line"><span style="color: #6272A4"> */</span></span>
<span class="line"><span style="color: #FF79C6">function</span><span style="color: #F8F8F2"> </span><span style="color: #50FA7B">postToFacebookPage</span><span style="color: #F8F8F2">($pageId, $accessToken, $content, $imagePath </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #BD93F9">null</span><span style="color: #F8F8F2">){</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Encode content as URL-safe string</span></span>
<span class="line"><span style="color: #F8F8F2">    $content </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD">urlencode</span><span style="color: #F8F8F2">($content);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Determine the endpoint and payload</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #FF79C6">if</span><span style="color: #F8F8F2"> ($imagePath) {</span></span>
<span class="line"><span style="color: #F8F8F2">        </span><span style="color: #6272A4">// If an image path is provided, post as a photo</span></span>
<span class="line"><span style="color: #F8F8F2">        $url </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">https://graph.facebook.com/</span><span style="color: #F8F8F2">$pageId</span><span style="color: #F1FA8C">/photos?url=</span><span style="color: #F8F8F2">$imagePath</span><span style="color: #F1FA8C">&amp;caption=</span><span style="color: #F8F8F2">$content</span><span style="color: #F1FA8C">&amp;access_token=</span><span style="color: #F8F8F2">$accessToken</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">;</span></span>
<span class="line"><span style="color: #F8F8F2">    } </span><span style="color: #FF79C6">else</span><span style="color: #F8F8F2"> {</span></span>
<span class="line"><span style="color: #F8F8F2">        </span><span style="color: #6272A4">// Otherwise, post as a regular feed message</span></span>
<span class="line"><span style="color: #F8F8F2">        $url </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #E9F284">&quot;</span><span style="color: #F1FA8C">https://graph.facebook.com/</span><span style="color: #F8F8F2">$pageId</span><span style="color: #F1FA8C">/feed?message=</span><span style="color: #F8F8F2">$content</span><span style="color: #F1FA8C">&amp;access_token=</span><span style="color: #F8F8F2">$accessToken</span><span style="color: #E9F284">&quot;</span><span style="color: #F8F8F2">;</span></span>
<span class="line"><span style="color: #F8F8F2">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Initialize cURL session</span></span>
<span class="line"><span style="color: #F8F8F2">    $ch </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD">curl_init</span><span style="color: #F8F8F2">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Set cURL options</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #8BE9FD">curl_setopt</span><span style="color: #F8F8F2">($ch,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">CURLOPT_URL</span><span style="color: #F8F8F2">,</span><span style="color: #50FA7B"> </span><span style="color: #F8F8F2">$url);</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #8BE9FD">curl_setopt</span><span style="color: #F8F8F2">($ch,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">CURLOPT_RETURNTRANSFER</span><span style="color: #F8F8F2">,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">true</span><span style="color: #F8F8F2">);</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #8BE9FD">curl_setopt</span><span style="color: #F8F8F2">($ch,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">CURLOPT_POST</span><span style="color: #F8F8F2">,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">true</span><span style="color: #F8F8F2">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Execute cURL session and capture the response</span></span>
<span class="line"><span style="color: #F8F8F2">    $response </span><span style="color: #FF79C6">=</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD">curl_exec</span><span style="color: #F8F8F2">($ch);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Check for cURL errors</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #FF79C6">if</span><span style="color: #F8F8F2"> (</span><span style="color: #8BE9FD">curl_errno</span><span style="color: #F8F8F2">($ch)) {</span></span>
<span class="line"><span style="color: #F8F8F2">        </span><span style="color: #FF79C6">throw</span><span style="color: #F8F8F2"> </span><span style="color: #FF79C6">new</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD; font-style: italic">Exception</span><span style="color: #F8F8F2">(</span><span style="color: #E9F284">&#39;</span><span style="color: #F1FA8C">cURL Error: </span><span style="color: #E9F284">&#39;</span><span style="color: #F8F8F2"> </span><span style="color: #FF79C6">.</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD">curl_error</span><span style="color: #F8F8F2">($ch));</span></span>
<span class="line"><span style="color: #F8F8F2">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Close cURL session</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #8BE9FD">curl_close</span><span style="color: #F8F8F2">($ch);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #6272A4">// Decode JSON response and return it</span></span>
<span class="line"><span style="color: #F8F8F2">    </span><span style="color: #FF79C6">return</span><span style="color: #F8F8F2"> </span><span style="color: #8BE9FD">json_decode</span><span style="color: #F8F8F2">($response,</span><span style="color: #50FA7B"> </span><span style="color: #BD93F9">true</span><span style="color: #F8F8F2">);</span></span>
<span class="line"><span style="color: #F8F8F2">}</span></span>
<span class="line"></span></code></pre></div>



<p>This will publish a post in Facebook on behalf of the user who allowed permission while generating API.</p>



<p>Here we have demonstrated using PHP language. But notice that we used <strong>CURL</strong> which can be used with any language like Python, Javascript, Java, C# (.Net), Go,  Rust, Ruby etc. Just use the <strong>CURL</strong> library of your favorite language. Then you can auto post in Facebook page with in language .</p>



<h2 class="wp-block-heading">Publish post every hour</h2>



<p>Now if you want to auto post in Facebook page like this every hour or particular period of time, you can simply use cron job. But mind that every API has a rate limit. Do not cross that limit least you should be imposed restriction from Facebook.</p>



<p>If you face any problem feel free to comment . </p>



<h3 class="wp-block-heading">Practical example</h3>



<p>I publish all the blog posts of <a href="https://mindila.xyz/blog" target="_blank" rel="noreferrer noopener">mindila.xyz/blog</a> using Facebook auto-publish mechanism.</p>



<h2 class="wp-block-heading">Business solution</h2>



<p>If you need business solution regarding Facebook page, groups etc. and graph API, you can contact our company email.</p>
<p>The post <a href="https://datamatric.com/blog/how-to-auto-post-in-facebook-page-using-graph-api/">How to auto publish post in Facebook page &#8211; using Graph API</a> appeared first on <a href="https://datamatric.com/blog"></a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://datamatric.com/blog/how-to-auto-post-in-facebook-page-using-graph-api/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
