Yii Development, Facebook API Interconnect login, ask the process
Yii Development, Facebook API Interconnect login, ask the specific process?
------Solution--------------------
Facebook session gets the SDK to do without writing it yourself.
The SDK should consist of the following three files
base_facebook.php
facebook.php
Fb_ca_chain_bundle.crt
Include "facebook.php";
$oFacebook = new Facebook (Array (
' AppId ' = ' xxx ',
' Secret ' = ' xxx ',
' Cookie ' =>true,
' FileUpload ' =>true
));
$user = $oFacebook->getuser ();
if ($user) {
try{
$user _profile = $oFacebook->api ('/'. $user);//Determine if access to user information
} catch (Facebookapiexception $e) {
$user = null;
}
if ($user) {
return $user;//returns User ID
}
}else{
$LOGINURL = $oFacebook->getloginurl (Array (
' Scope ' = ' xxxx ',//fill in the permissions here, to get something such as Publish_stream,user_photos,email,offline_access,user_birthday,user_notes
' Redirect_uri ' + ' xxx ' //Here are the addresses that are filled in after Facebook login to jump back
));
return $LOGINURL;
}
?>
After getting $loginurl, jump to this address
When Facebook is successfully logged in, it returns to the Redirect_uri address and takes the parameters back to
Redirect_uri PHP can write like this
$userid = $oFacebook->getuser ();
$facebook _accesstoken = $facebook->getaccesstoken ();
echo $facebook _accesstoken. '
';
try{
$param = Array (
' Method ' = ' fql.query ',
' Query ' = ' "select ' uid,name,pic,pic_square,email,sex,birthday_date ' from user WHERE uid= '". $userid. "'",
' Access_token ' = $facebook _accesstoken
);
$result = Ofacebook->api ($param);
} catch (Facebookapiexception $e) {
return Array ();
}
if ($result) {
$user _profile = Array ();
foreach ($result [0] as $key = + $val) {
$user _profile[$key] = $val;
}
return $user _profile;
}else{
return Array ();
}
Print_r ($result);
?>
The rest is the operation of the server over there.