1

I have a website with a standard PHP login system, nothing special, but would like to allow people to use Facebook to login and/or register to it, but with no success.

There are so many options, I don't know which one to use. I'm fairly sure I could get the right one working, but I literally don't know where to start.

I've successfully registered an app and got an app key and secret key. I then tried the facebook login button as here: https://developers.facebook.com/docs/guides/web/#login - but that didn't appear ideal as I wasn't certain how to store the data.

Then I checked the Graph API and I think that's what I need. I've got the code able to give me an access_token which I can then store in a mySQL database. I can then access https://graph.facebook.com/me?access_token=HOOP_DE_DOOT_DE_FRUIT and get a big JSON list of stuff, which is obviously relative to the permissions I've asked for.

Is the access_token method the correct method? Of course, once I have it, I can just bung the token in the DB, store it along with the email address and then access the user's information but I'm not sure if that's secure for logins, though it'll speed up registration because I can pre-fill all the fields.

How should I be using the access_token to actually login a user, assuming that I can successfully get it and store it in a mySQL database with the corresponding email address?

4

1 に答える 1

1

データベースを使用してユーザーにログインしようとしている場合、ユーザー ID を取得する必要があります。これは、次のように PHP で行うことができます。

require_once(BASE_PATH . "facebook.php");
$facebook = new Facebook( array('appId'=>'appId', 
                        'secret'=>'secret', 
                        'cookie'=>false) );
$fbid = $facebook->getUser();

または、次のようにフロントエンドでログインできます。

FB.login(function(response){
        //Log them in
            if(response.authResponse){
            //They're now logged in
                var uid = response.authResponse.userID;
            }
}

そして、ajax 呼び出しなどを使用して、ID をバックエンドに戻します。

于 2012-08-13T22:50:52.237 に答える