Share application request with facebook API in codeigniter

Share application request with facebook API in codeigniter.
In this small tutorial I will explain you how to share your website notification to facebook friends and when the user click on the notification he will be redirected to your website. Some important point to remember before we start.Share your post on facebook with facebook API appRequest method.
1) The url need to be SSL secured (https://yourwebsite.com).Facebook do not allow the unsecured url to canvas url.

Now let’s start.
Create facebook application on https://developer.facebook.com register yourself and create an application.after creating the application you will see the App ID and App Secret. app ID which will be required to share the your application.
Now click on the application setting.

You will see the add platform click on it and select website and fill your website url.

click again on add platform and select facebook canvas.There will be a field Secure Canvas URL field fill the canvas url of your website(https://yourwebsite.com) and in the end of the url add test.html/?fb it will help you to redirect the user to your website.
now your full url will look like this
(https://yourwebsite.com/test.html?fb)
Now save it.
In next step click on the app details and select the category to games and subcategory anything.
now click on status and review and click on the yes button to activate the application.

Now create facebookshare.php file and paste the below code:
in front of app ID enter the app ID of your application which you created earlier.

<html xmlns:fb="http://www.facebook.com/2008/fbml">
 <body>
 <script src="http://connect.facebook.net/en_US/all.js"></script>
 <div id="fb-root"></div>
 <script>
 function FacebookInviteFriends()
 {
FB.init({appId: '1234567890', xfbml: true, cookie: true});
FB.ui({
 method: 'apprequests',
 message: 'Your message here'
 }, function(response){
 console.log(response);
 });
}
 </script>
<a href='#' onclick="FacebookInviteFriends();"> Facebook Invite Friends</a>
 </body>
 </html>
 
Now create the test.html file on the root of your website.This is very important to redirect the user to your website.copy and paste the

following code in the file.

<html> <body>
 You are being redirected. 
If not <a href="http://yourwebsite.com" target="_top">click here</a>.
  <script>
window.top.location.href = "http://yourwebsite.com";</script> </body>
 </html>

When user will click on the your application notification request user will be redirected to your website.
Important thing to re>member this might be against the facebook policy to redirect user to your website from
facebook directly.Please read the facebook policy before doing this.

  • Pingback: Send private message using facebook API()

  • Janne Kankkunen

    This seems like a perfect example but for some reason when I use this in my Facebook app nothing happens when clicking the link. My app is set as a game and I copy-pasted that code to the file I am using, so there is nothing else in that file. What could be causing this problem?

  • Janne Kankkunen

    Forgot to mention that, yes I did change the app-id to my own app’s id :)