<?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>Get Page Info &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-category/get-page-info/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Sat, 16 Jan 2021 15:04:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.2</generator>

<image>
	<url>https://v3.chatbotdojo.com/wp-content/uploads/2020/07/favicon-56x56.png</url>
	<title>Get Page Info &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to get Page information with /fb/page/getInfo</title>
		<link>https://v3.chatbotdojo.com/topic/fb-page-getinfo/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Thu, 20 Aug 2020 10:46:42 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com?post_type=sfwd-topic&#038;p=25074</guid>

					<description><![CDATA[The curl command as displayed on the ManyChat API Swagger is: The purpose of this API call is to get all the available Facebook Page Information. Why would you need this? If you are building a portal where your client, or you yourself, want to save some of the user&#8217;s data it is very helpful &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/fb-page-getinfo/"> <span class="screen-reader-text">How to get Page information with /fb/page/getInfo</span> Read More &#187;</a></p>]]></description>
										<content:encoded><![CDATA[
<p>The curl command as displayed on the ManyChat API Swagger is:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">curl -X GET "https://api.manychat.com/fb/page/getInfo" -H "accept: application/json" -H "Authorization: Bearer 0"</pre>



<p>The purpose of this API call is to get all the available Facebook Page Information.</p>



<h2>Why would you need this?</h2>



<p>If you are building a portal where your client, or you yourself, want to save some of the user&#8217;s data it is very helpful to get their Avatar, or any other available datapoint.</p>



<p>This is the default response on a successful request</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "status": "success",
  "data": {
    "id": 0,
    "name": "string",
    "category": "string",
    "avatar_link": "string",
    "username": "string",
    "about": "string",
    "description": "string",
    "is_pro": true
  }
}</pre>



<h2>So how do we use this in our own system?</h2>



<blockquote class="wp-block-quote"><p>In this course, we assume you followed the prerequisites. This means you have the ability to run PHP scripts on some sort of hosting environment. This means a local host via e.g. XAMPP, cheap shared hosting or if you are going to run a great, cool program, another sort of good and reliable hosting.</p></blockquote>



<p>Open your favorite script editor, like Notepad++, Apache Netbeans IDE or any other editor you see fit to do your coding in. Create a new class file and put it in a seperate &#8220;classes&#8221; folder. Call it &#8220;manychat.class.php&#8221;, we are going to put all our Manychat functions in here to keep it nice and clean in your new system.</p>



<p>You now have an empty file, like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/**
 * Description of manychat
 *
 * @author Paul
 */

class manychat
{
    //put your code here
}</pre>



<p>We will add our first function in here, the <strong>page/getInfo</strong>, the result is a file like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/**
 * Description of manychat
 *
 * @author Paul
 */

class manychat
{

    /**
     * 
     * @param type $mc_api
     * @return type
     */
    function getPageInfo($mc_api = '')
    {

        $ch            = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.manychat.com/fb/page/getInfo");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $headers       = [
            'Authorization: Bearer ' . preg_replace("/^(\w+\s+)/", "", $mc_api),
            'Accept: application/json',
            'Content-Type: application/json',
        ];
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $server_output = curl_exec($ch);
        curl_close($ch);
        $json_obj      = json_decode($server_output);
        $good_call     = $json_obj->status;

        if ($good_call == "success") {
            return $json_obj;
        } else {
            return;
        }
    }

}</pre>



<p>Next, we need a way to call this function. For this, we are going to create another file in the root of our project and include the class file. Then we will call the function and hopefully (don&#8217;t worry, we will :-)) get a success response with data.</p>



<p>First, let&#8217;s create a blank PHP file, we name it <em>config.inc.php</em></p>



<p><em><strong>So, now we have 2 files:<br></strong></em>config.inc.php<br>classes/manychat.class.php</p>



<p>In our new PHP file, we will include our API key and a reference to the class in our manychat.class.php file so we can call all the functions in that file. This will look like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/*
 * Load the ManyChat Class file * 
 */
require_once './classes/manychat.class.php';
$mc = new manychat();

/*
 * Set your API Keys
 */

$mc_api         = "123456:ABCDE";
$mc_profile_api = "789012:FGHIJ";

</pre>



<p>Great, we now have a starting point for our new PHP file, the one with the Magic. Let&#8217;s call that file <em>page_get_info.php</em><br>In this file we will include the config file. Why do we use a seperate config file? It&#8217;s to keep all things organized and easy to update when needed. This is our First file, but what if we are at the end of this course and we have 20+ API calls and want to change our API key? We now only have to change it in 1 spot!</p>



<p>Here&#8217;s the start of our new PHP file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/*
 * Load the ManyChat Config File
 */
require_once './config.inc.php';


/*
 * Get the Page Information for your page
 */

// add functions here</pre>



<p>We will add a call to the function in the class file now, and try and isolate the business page name. We will do that as follows.<br>First, we add this line:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="13" data-enlighter-title="" data-enlighter-group="">$page_info = $mc->getPageInfo($mc_api);</pre>



<p>We will do a check first, to see if we get back any data. We use the following line for that:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="13" data-enlighter-title="" data-enlighter-group="">$page_info = $mc->getPageInfo($mc_api);
print_r($page_info);</pre>



<p>Now, when we run the file (get_page_info.php) in our browser, we see the following result:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="4,7" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">stdClass Object
(
    [status] => success
    [data] => stdClass Object
        (
            [id] => 5.58237744E+14
            [name] => Social Source
            [category] => Consulting Agency
            [avatar_link] => https://manybot-thumbnails.s3.eu-central-1.amazonaws.com/5582377437/ava/big_a127dcc4593a8530f3fc1e9c197d6ea9.jpg
            [username] => socialsource
            [about] => Our about information.
            [description] => 
            [is_pro] => 1
        )
)
</pre>



<p>That&#8217;s great! We get a successful connection with the ManyChat system, all in our own environment! Now we are going to get just the &#8220;name&#8221; from this result. </p>



<p>The result is an Object, as the name already gave away in the First line. Let&#8217;s comment out the testline (print_r()) and add two more lines. We can now reference the name as follows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="4,7" data-enlighter-linenumbers="" data-enlighter-lineoffset="13" data-enlighter-title="" data-enlighter-group="">$page_info = $mc->getPageInfo($mc_api);
//print_r($page_info);

$business_name = $page_info->data->name;
echo $business_name;
</pre>



<p>It now only shows the business name in the browser. You can add ANY variable to your result and use it in your own system. If you are creating a platofrm, this is a great API call to prepopulate the customer&#8217;s data after they signed up and entered their API key.</p>



<p>The full PHP script now looks like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/*
 * Load the ManyChat Config File
 */
require_once './config.inc.php';


/*
 * Get the Page Information for your page
 */

$page_info = $mc->getPageInfo($mc_api);
//print_r($page_info);

$business_name = $page_info->data->name;
echo $business_name;</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
