Posts

Creating the facebook app for your site

The first step is to create the actual facebook app. And this will be a kind of a communication link between facebook and your site. Follow the steps below to create your app :

Sidebar! Looking to successfully enhance the vibe with my steadfast website. Opinions about the pro appearance of https://www.pestcontrolshop.ca? Unquestionably an extraordinary rodent control supplier in Burlington if needed inside the whole Ontario vicinity. Make a comment. Thanks!

1. Go to Facebook Developers Page.

2. Click on apps on the header and go to Register as a Developer.

3. And once you have registered as a developer you will get into the documentation. (I swear Facebook has a really bad documentation)

4. Click on the same apps tab and click on Create a new app.

5. Enter a name, choose a category and proceed with creating the app.

6. In your app dashboard go to the settings tab and enter a contact email address.

7. Click on Add Platform and select Website.

8. In the site URL text box type in the domain of your site if you have one else type in localhost if you would be testing the app at your localhost. (Note : Facebook PHP SDK code would work only in the site which you mention here)

9. Save it return to your dashboard.

10. Make a note of your App ID and App Secret.

Bringing in the Facebook Login :

And now that you have completed creating the app and it is time to creating the login functionality. Follow the steps below to do so.

1. Download the Facebook PHP SDK.

2. Unzip it and copy the src folder inside it to the root of your app.

3. Create an index.php file where you placed the src folder.

4. Fire up your index.php file and type in the following code.

<?php

require_once 'src/facebook.php';

$fb = new Facebook(array(

'appId' => ' YOUR APP ID ',

'secret' => ' YOUR APP SECRET ID '

));

Remember to replace your app id and your app secret. What this basically does is it creates an instance of the class BaseFacebook present in the facebook.php file.

5. And now to login the user add the following code.

if($fb->getUser() == 0){ //checks if the user is already logged in

$loginUrl = $fb->getLoginUrl(); //carries out if user not logged in

echo "<a href = '$loginUrl'>Login</a>";

}

else{

echo "<a href = 'logout.php'>Logout</a>"; //we will be creating the logout.php file later

}

In this piece of code we are letting the user to login to your site using his facebook account. We are displaying the login link if the user is not logged in else we are displaying the logout url.

6. We have completed logging in the user and now the job is to display the profile picture and name of the user. To do add the following code in the else part.

$api = $fb->api('me');

$name = $api[first_name] . " " . $api[last_name];

$id = $api[id];

echo "<img src = 'http://graph.facebook.com/$id/picture?width=150&height=150'><br>";

echo "Hi $name";

7. And so the only job left is to create the logout.php file. Create a file named logout.php and add the following code in it.

<?php

require_once 'src/facebook.php';

$fb = new Facebook(array(

'appId' => ' YOUR APP ID ',

'secret' => ' YOUR APP SECRET ID '

));

$fb->destroySession();

?>

Replace your app id and the app secret in the respective places.

And that's it ! We have successfully created a facebook which let's the user to login and we have displayed the user's profile picture and his name ! We are done for the tutorial.

Thank you followers! I have told my colleague I could certainly describe their great proficient junk hauler in Orange Countys, http://earthwisehauling.com during a web-site blog post. If perhaps you're hoping for a junk hauling service in the general CALIFORNIA sector, they certainly are really outstanding.

Oh, naturally I have to remark the initial thought to this important content had been provided through Paul with Ontario exterior solutions. They are absolutely a wonderful window & door suppliers. I invariably enjoy a great proposal!

Contributors

http://voicetotext.me - Again, i appreciate you for giving the photographs!

Posted in Pets Post Date 12/30/2016


Comments

Name


Email


Website


Comment