Home >php教程 >php手册 >facebook登录for ThinkSDK

facebook登录for ThinkSDK

WBOY
WBOYOriginal
2016-06-07 11:41:261518browse

由于工作需要用到国外的一些联合账号登录,因此针对ThinkSDK增加了facebook登录的封装
使用方法参考 https://github.com/Aoiujz/ThinkSDK

直接贴代码<?php <br /> <br> /**<br>  * Facebook登录<br>  * @author wangdong<br>  * @ctime 2014-07-15<br>  */<br> class FacebookSDK extends ThinkOauth{<br>     /**<br>      * 获取requestCode的api接口<br>      * @var string<br>      */<br>     protected $GetRequestCodeURL = 'https://www.facebook.com/dialog/oauth';<br> <br>     /**<br>      * 获取access_token的api接口<br>      * @var string<br>      */<br>     protected $GetAccessTokenURL = 'https://graph.facebook.com/oauth/access_token';<br> <br>     /**<br>      * 获取request_code的额外参数 URL查询字符串格式<br>      * @var srting<br>      */<br>     protected $Authorize = 'scope=email';<br> <br>     /**<br>      * API根路径<br>      * @var string<br>      */<br>     protected $ApiBase = 'https://graph.facebook.com/';<br> <br>     /**<br>      * 组装接口调用参数 并调用接口<br>      * @param  string $api    微博API<br>      * @param  string $param  调用API的额外参数<br>      * @param  string $method HTTP请求方法 默认为GET<br>      * @param  bool   $multi<br>      * @return array<br>      */<br>     public function call($api, $param = '', $method = 'GET', $multi = false){<br>         /*  facebook 调用公共参数 */<br>         $params = array('access_token'=>$this->Token['access_token']);<br>         $header = array();<br> <br>         $data = $this->http($this->url($api), $this->param($params, $param), $method, $header);<br>         return json_decode($data, true);<br>     }<br>     <br>     /**<br>      * 解析access_token方法请求后的返回值<br>      * @param string $result 获取access_token的方法的返回值<br>      * @param mix    $extend<br>      * @return array<br>      */<br>     protected function parseToken($result, $extend){<br>         parse_str($result, $data);<br>         if(is_array($data) && $data['access_token'] && $data['expires']){<br>             $this->Token = $data;<br>             $data['openid'] = $this->openid();<br>             return $data;<br>         }else{<br>             throw new Exception("获取 facebook ACCESS_TOKEN出错:未知错误");<br>         }<br> <br>     }<br>     <br>     /**<br>      * 获取当前授权应用的openid<br>      * @return string<br>      */<br>     public function openid(){<br>         if(isset($this->Token['openid']))<br>             return $this->Token['openid'];<br>         <br>         $data = $this->call('me');<br>         if(!empty($data['id']))<br>             return $data['id'];<br>         else<br>             throw new Exception('没有获取到 facebook 用户ID!');<br>     }<br>     <br> }

附件 FacebookSDK.class.tar.gz ( 1.03 KB 下载:171 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn