{"id":1137,"date":"2012-08-17T06:05:31","date_gmt":"2012-08-17T06:05:31","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1137"},"modified":"2012-08-17T18:47:33","modified_gmt":"2012-08-17T18:47:33","slug":"how-to-add-a-custom-application-tab-to-facebook-fan-page","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2012\/08\/how-to-add-a-custom-application-tab-to-facebook-fan-page\/","title":{"rendered":"PHP &#8211; Add a custom application tab to facebook fan page ?"},"content":{"rendered":"<p>I spend a lot of time fingering out how to add &#8220;Custom Tab&#8221; in face-book fan page.<br \/>\nIn fact this is very easy through PhpFacebook API. <\/p>\n<p>You need to have &#8220;manage_pages&#8221; permission during user authorization. <\/p>\n<p>This code will allow you to  get control of all fab pages. This code is good for someone who is willing to add his tab\/app to fab page. This is not good for normal user. <\/p>\n<pre lang=\"php\">\r\n$logoutUrl = $facebook->getLogoutUrl();\r\n\r\n\t$params = array(\r\n\t\t 'scope' => 'offline_access, email, publish_stream, manage_pages',\r\n\t\t'redirect_uri' => 'https:\/\/apps.facebook.com\/your-app-name\/'\r\n\t); \r\n<\/pre>\n<p>\tIf you logged in successfully this code will show you all fan pages with Id and names etc.<\/p>\n<pre lang=\"php\">\r\n$pageIds=$facebook->api('\/me\/accounts');\r\n\r\nprint_r($pageIds); \/\/ this will show you array data. This is key part and show you access_token which is very imp.\r\n\r\n\r\n         [0] => Array\r\n                (\r\n                    [name] => My App Tester\r\n                    [access_token] => AAAD3pm1y4sQBADkZA4mT1UNFzUyQZBw9g1aH2CCriZCAHyqmP6rvHurcZC0qShvPFhPB0R4CWP7TMxVzHp2ktepcrM1XZBheZCoZD\r\n                    [category] => Computers\/internet\r\n                    [id] => 56789349409295678\r\n                    [perms] => Array\r\n                        (\r\n                            [0] => ADMINISTER\r\n                            [1] => EDIT_PROFILE\r\n                            [2] => CREATE_CONTENT\r\n                            [3] => MODERATE_CONTENT\r\n                            [4] => CREATE_ADS\r\n                            [5] => BASIC_ADMIN\r\n                        )\r\n\r\n                )\r\n\r\n$pageAccessToken=$pageIds[\"data\"][1][\"access_token\"];\r\n<\/pre>\n<p>Now it is time to post you can use Ajax or any way you like to post. PAGE_ID is your fan page ID\/56789349409295678. <\/p>\n<pre lang=\"php\">\r\n$facebook->api(\"\/PAGE_ID\/tabs\",\"post\", array(\"access_token\" => $pageAccessToken,  \"app_id\" => $appId));\r\n<\/pre>\n<p>Now you can store PAGE_ID in database and when you will run this code then one tab will be added in your fan page. <\/p>\n<p>Now your user can access whatever you add in your app. <\/p>\n<p>use this code in your app page to correlate custom app for different user since you already have PAGE_ID stored in db<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\r\nfunction parse_signed_request($signed_request, $secret) {\r\n  list($encoded_sig, $payload) = explode('.', $signed_request, 2); \r\n\r\n  \/\/ decode the data\r\n  $sig = base64_url_decode($encoded_sig);\r\n  $data = json_decode(base64_url_decode($payload), true);\r\n\r\n  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {\r\n    error_log('Unknown algorithm. Expected HMAC-SHA256');\r\n    return null;\r\n  }\r\n\r\n  \/\/ check sig\r\n  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);\r\n  if ($sig !== $expected_sig) {\r\n    error_log('Bad Signed JSON signature!');\r\n    return null;\r\n  }\r\n\r\n  return $data;\r\n}\r\n\r\nfunction base64_url_decode($input) {\r\n  return base64_decode(strtr($input, '-_', '+\/'));\r\n}\r\n\r\n$signed_request = $_REQUEST[\"signed_request\"];\r\n$secret = $fb_app_secret;\r\n\r\necho \"<pre>\";\r\n\r\nprint_r(parse_signed_request($signed_request, $secret));\r\n?>\r\n<\/pre>\n<p>Using this method you can create multiuser fab page tab application and make some money by adding extra features!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spend a lot of time fingering out how to add &#8220;Custom Tab&#8221; in face-book fan page. In fact this is very easy through PhpFacebook API. You need to have &#8220;manage_pages&#8221; permission during user authorization. This code will allow you to get control of all fab pages. This code is good for someone who is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[44],"tags":[],"class_list":["post-1137","post","type-post","status-publish","format-standard","hentry","category-facebook-php-api"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1137"}],"version-history":[{"count":4,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1139,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions\/1139"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}