0
votes

I'm using the Facebook Graph Toolkit and developing codeigniter website.

I want to create and design a website that has registration that will use a Facebook account as an alternative to my website login/registration.

I am thinking of just storing the Facebook User ID who has approved the use of the FB app in order to identify the user for next time when he/she logs in to my website using his Facebook account.

Scenario here is:

  1. Any browser, user already logged in to his Facebook account (say browser Tab no.1).

  2. Same browser, Tab no.2, user visits my website (he has already registered to my website using his Facebook account, as I store his Facebook ID).

  3. Upon his visit to my website home page, the top corner will display his account name (this indicates that he has logged in to my website even though he has only logged in to Facebook, but never visited my website and clicked on the Login button).

So my question is, how to achieve the scenario of step no.3?

1
just launch the fb login mechanism on page load it will do the login process automatically. If the user isn't logged in it will show the login dialog instead. - Rohit Batra
How does he register on your website in step 2 but have never visited your website in step 3? - ceejayoz

1 Answers

1
votes

You can achieve this in following code in JavaScript.

In the below code . Inside (response.status === 'connected') condition you can achieve the scenario of step no.3 and in response.status === 'not_authorized' condition you can call fb login for him to authorize your app if he is not. Try reading Facebook developer document. You can get a clear idea of your needs.

FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token 
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook, 
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});