yii开发, Facebook api 互联登录,请教流程
yii开发, Facebook api 互联登录,请教一下具体流程?
------解决方案--------------------
facebook session获取 sdk会做,不用自己写。
sdk应该包含以下三个文件
base_facebook.php
facebook.php
fb_ca_chain_bundle.crt
<br /><?php<br />include "facebook.php";<br />$oFacebook = new Facebook(array(<br /> 'appId' => 'xxx',<br /> 'secret' => 'xxx',<br /> 'cookie' => true,<br /> 'fileUpload' => true<br /> ));<br /><br />$user = $oFacebook->getUser();<br />if($user){<br /> try{<br /> $user_profile = $oFacebook->api('/'.$user); //判斷是否獲取到用戶信息<br /> } catch (FacebookApiException $e){<br /> $user = null;<br /> }<br /> if($user){<br /> return $user; //返回用戶id<br /> }<br />}else{<br /> $loginUrl = $oFacebook->getLoginUrl(array(<br /> 'scope' => 'xxxx', // 这里填权限,要获取的东西 例如 publish_stream,user_photos,email,offline_access,user_birthday,user_notes<br /> 'redirect_uri' => 'xxx' // 这里填在facebook login后要回跳的地址<br /> ));<br /> return $loginUrl;<br />}<br />?><br />
<br /><?php<br /> $userid = $oFacebook->getUser();<br /><br /> $facebook_accesstoken = $facebook->getAccessToken();<br /> echo $facebook_accesstoken.'<br>';<br /><br /> try{<br /> $param = array(<br /> 'method' => 'fql.query',<br /> 'query' => "SELECT 'uid,name,pic,pic_square,email,sex,birthday_date' FROM user WHERE uid='".$userid."'",<br /> 'access_token' => $facebook_accesstoken<br /> );<br /> $result = oFacebook->api($param);<br /> } catch(FacebookApiException $e){<br /> return array();<br /> }<br /><br /> if($result){<br /> $user_profile = array();<br /> foreach($result[0] as $key=>$val){<br /> $user_profile[$key] = $val;<br /> }<br /> return $user_profile;<br /> }else{<br /> return array();<br /> } <br /> print_r($result);<br />?><br />