Yii Development, Facebook API Interconnect login, ask the process

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.