热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

部分主流sns平台的账号登录及api操作

新浪微博、腾讯微博、QQ、人人网、开心网、网易微博、豆瓣、百度、Google、微软、Instagram、Facebook、360、GitHub等平台的账号登录及api操作ÿ

新浪微博、腾讯微博、QQ、人人网、开心网、网易微博、豆瓣、百度、Google、微软、Instagram、Facebook、360、GitHub等平台的账号登录及api操作,使用oauth 2.0
官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录、获取个人信息、发布微博等功能,如果需要其他功能可以根据官方的api文档自行添加

2012-12-30:增加示例文件

2012-12-31:增加Facebook

2013-04-02:更新QQ、人人网、开心网、豆瓣、百度、Google、微软、Facebook

2013-05-09:增加GitHub

代码已提交到GIt @ OSC:http://git.oschina.net/piscdong/sns_php,这里将不再更新

 

源码与演示:源码出处

 

1. [文件] 新浪微博 ~ 4KB

/*** PHP Library for weibo.com** @author PiscDong (http://www.piscdong.com/)*/
class sinaPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://api.weibo.com/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://api.weibo.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}/**function access_token_refresh($refresh_token){}**/function get_uid(){$params=array();$url='https://api.weibo.com/2/account/get_uid.json';return $this->api($url, $params);}function show_user_by_id($uid){$params=array('uid'=>$uid);$url='https://api.weibo.com/2/users/show.json';return $this->api($url, $params);}function statuses_count($ids){$params=array('ids'=>$ids);$url='https://api.weibo.com/2/statuses/count.json';return $this->api($url, $params);}function get_comments_by_sid($id, $count=10, $page=1){$params=array('id'=>$id,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/comments/show.json';return $this->api($url, $params);}function repost_timeline($id, $count=10, $page=1){$params=array('id'=>$id,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/statuses/repost_timeline.json';return $this->api($url, $params);}function update($img_c, $pic=''){$params=array('status'=>$img_c);if($pic!='' && is_array($pic)){$url='https://api.weibo.com/2/statuses/upload.json';$params['pic']=$pic;}else{$url='https://api.weibo.com/2/statuses/update.json';}return $this->api($url, $params, 'POST');}function user_timeline($uid, $count=10, $page=1){$params=array('uid'=>$uid,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/statuses/user_timeline.json';return $this->api($url, $params);}function querymid($id, $type=1, $is_batch=0){$params=array('id'=>$id,'type'=>$type,'is_batch'=>$is_batch);$url='https://api.weibo.com/2/statuses/querymid.json';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{if(isset($params['pic'])){uksort($params, 'strcmp');$str_b=uniqid('------------------');$str_m='--'.$str_b;$str_e=$str_m. '--';$body='';foreach($params as $k=>$v){if($k=='pic'){if(is_array($v)){$img_c=$v[2];$img_n=$v[1];}elseif($v{0}=='@'){$url=ltrim($v, '@');$img_c=file_get_contents($url);$url_a=explode('?', basename($url));$img_n=$url_a[0];}$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k.'"; filename="'.$img_n.'"'."\r\n";$body.="Content-Type: image/unknown\r\n\r\n";$body.=$img_c."\r\n";}else{$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k."\"\r\n\r\n";$body.=$v."\r\n";}}$body.=$str_e;$headers[]="Content-Type: multipart/form-data; boundary=".$str_b;$result=$this->http($url, $body, 'POST', $headers);}else{$result=$this->http($url, http_build_query($params), 'POST');}}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: sinaPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

 

2. [文件] 腾讯微博 ~ 5KB

/*** PHP Library for t.qq.com** @author PiscDong (http://www.piscdong.com/)*/
class tqqPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL, $openid&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;$this->openid&#61;$openid;}function login_url($callback_url){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url);return &#39;https://open.t.qq.com/cgi-bin/oauth2/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://open.t.qq.com/cgi-bin/oauth2/access_token?&#39;.http_build_query($params);$result_str&#61;$this->http($url);$json_r&#61;array();if($result_str!&#61;&#39;&#39;)parse_str($result_str, $json_r);return $json_r;}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id);$url&#61;&#39;https://open.t.qq.com/cgi-bin/oauth2/access_token?&#39;.http_build_query($params);$result_str&#61;$this->http($url);$json_r&#61;array();if($result_str!&#61;&#39;&#39;)parse_str($result_str, $json_r);return $json_r;}function me(){$params&#61;array();$url&#61;&#39;https://open.t.qq.com/api/user/info&#39;;return $this->api($url, $params);}function getgetMyTweet($reqnum&#61;10, $pageflag&#61;0){$params&#61;array(&#39;pageflag&#39;&#61;>$pageflag,&#39;reqnum&#39;&#61;>$reqnum);$url&#61;&#39;https://open.t.qq.com/api/statuses/broadcast_timeline&#39;;return $this->api($url, $params);}function getRecount($ids){$params&#61;array(&#39;ids&#39;&#61;>$ids,&#39;flag&#39;&#61;>2);$url&#61;&#39;https://open.t.qq.com/api/t/re_count&#39;;return $this->api($url, $params);}function getReplay($id, $flag&#61;0, $f&#61;0, $n&#61;10){$params&#61;array(&#39;rootid&#39;&#61;>$id,&#39;pageflag&#39;&#61;>$f,&#39;reqnum&#39;&#61;>$n,&#39;flag&#39;&#61;>$flag);$url&#61;&#39;https://open.t.qq.com/api/t/re_list&#39;;return $this->api($url, $params);}function postOne($img_c, $pic&#61;&#39;&#39;){$params&#61;array(&#39;content&#39;&#61;>$img_c);if($pic!&#61;&#39;&#39; && is_array($pic)){$url&#61;&#39;https://open.t.qq.com/api/t/add_pic&#39;;$params[&#39;pic&#39;]&#61;$pic;}else{$url&#61;&#39;https://open.t.qq.com/api/t/add&#39;;}return $this->api($url, $params, &#39;POST&#39;);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;oauth_consumer_key&#39;]&#61;$this->client_id;$params[&#39;access_token&#39;]&#61;$this->access_token;$params[&#39;openid&#39;]&#61;$this->openid;$params[&#39;clientip&#39;]&#61;$this->getIP();$params[&#39;oauth_version&#39;]&#61;&#39;2.a&#39;;$params[&#39;format&#39;]&#61;&#39;json&#39;;$params[&#39;scope&#39;]&#61;&#39;all&#39;;if($method&#61;&#61;&#39;GET&#39;){$result_str&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{if(isset($params[&#39;pic&#39;])){uksort($params, &#39;strcmp&#39;);$str_b&#61;uniqid(&#39;------------------&#39;);$str_m&#61;&#39;--&#39;.$str_b;$str_e&#61;$str_m. &#39;--&#39;;$body&#61;&#39;&#39;;foreach($params as $k&#61;>$v){if($k&#61;&#61;&#39;pic&#39;){if(is_array($v)){$img_c&#61;$v[2];$img_n&#61;$v[1];}elseif($v{0}&#61;&#61;&#39;&#64;&#39;){$url&#61;ltrim($v, &#39;&#64;&#39;);$img_c&#61;file_get_contents($url);$url_a&#61;explode(&#39;?&#39;, basename($url));$img_n&#61;$url_a[0];}$body.&#61;$str_m."\r\n";$body.&#61;&#39;Content-Disposition: form-data; name&#61;"&#39;.$k.&#39;"; filename&#61;"&#39;.$img_n.&#39;"&#39;."\r\n";$body.&#61;"Content-Type: image/unknown\r\n\r\n";$body.&#61;$img_c."\r\n";}else{$body.&#61;$str_m."\r\n";$body.&#61;&#39;Content-Disposition: form-data; name&#61;"&#39;.$k."\"\r\n\r\n";$body.&#61;$v."\r\n";}}$body.&#61;$str_e;$headers[]&#61;"Content-Type: multipart/form-data; boundary&#61;".$str_b;$result_str&#61;$this->http($url, $body, &#39;POST&#39;, $headers);}else{$result_str&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}}$json_r&#61;array();if($result_str!&#61;&#39;&#39;)$json_r&#61;json_decode($result_str, true);return $json_r;}function getIP(){if(isset($_ENV[&#39;HTTP_CLIENT_IP&#39;])){$ip&#61;$_ENV[&#39;HTTP_CLIENT_IP&#39;];}elseif(isset($_ENV[&#39;HTTP_X_FORWARDED_FOR&#39;])){$ip&#61;$_ENV[&#39;HTTP_X_FORWARDED_FOR&#39;];}elseif(isset($_ENV[&#39;REMOTE_ADDR&#39;])){$ip&#61;$_ENV[&#39;REMOTE_ADDR&#39;];}else{$ip&#61;$_SERVER[&#39;REMOTE_ADDR&#39;];}if(strstr($ip, &#39;:&#39;)){$ipa&#61;explode(&#39;:&#39;, $ip);foreach($ipa as $v){if(strlen($v)>7)$ip&#61;$v;}}if(strlen($ip)<7)$ip&#61;&#39;0.0.0.0&#39;;return $ip;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: tqqPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);return $response;}
}

 

3. [文件] QQ ~ 3KB

/*** PHP Library for qq.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class qqPHP
{function __construct($appid, $appkey, $access_token&#61;NULL){$this->appid&#61;$appid;$this->appkey&#61;$appkey;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;client_id&#39;&#61;>$this->appid,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;scope&#39;&#61;>$scope);return &#39;https://graph.qq.com/oauth2.0/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;client_id&#39;&#61;>$this->appid,&#39;client_secret&#39;&#61;>$this->appkey,&#39;code&#39;&#61;>$code,&#39;state&#39;&#61;>&#39;&#39;,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://graph.qq.com/oauth2.0/token?&#39;.http_build_query($params);$result_str&#61;$this->http($url);$json_r&#61;array();if($result_str!&#61;&#39;&#39;)parse_str($result_str, $json_r);return $json_r;}/**function access_token_refresh($refresh_token){}**/function get_openid(){$params&#61;array(&#39;access_token&#39;&#61;>$this->access_token);$url&#61;&#39;https://graph.qq.com/oauth2.0/me?&#39;.http_build_query($params);$result_str&#61;$this->http($url);$json_r&#61;array();if($result_str!&#61;&#39;&#39;){preg_match(&#39;/callback\(\s&#43;(.*?)\s&#43;\)/i&#39;, $result_str, $result_a);$json_r&#61;json_decode($result_a[1], true);}return $json_r;}function get_user_info($openid){$params&#61;array(&#39;openid&#39;&#61;>$openid);$url&#61;&#39;https://graph.qq.com/user/get_user_info&#39;;return $this->api($url, $params);}function add_share($openid, $title, $url, $site, $fromurl, $images&#61;&#39;&#39;, $summary&#61;&#39;&#39;){$params&#61;array(&#39;openid&#39;&#61;>$openid,&#39;title&#39;&#61;>$title,&#39;url&#39;&#61;>$url,&#39;site&#39;&#61;>$site,&#39;fromurl&#39;&#61;>$fromurl,&#39;images&#39;&#61;>$images,&#39;summary&#39;&#61;>$summary);$url&#61;&#39;https://graph.qq.com/share/add_share&#39;;return $this->api($url, $params, &#39;POST&#39;);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;$params[&#39;oauth_consumer_key&#39;]&#61;$this->appid;$params[&#39;format&#39;]&#61;&#39;json&#39;;if($method&#61;&#61;&#39;GET&#39;){$result_str&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result_str&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}$result&#61;array();if($result_str!&#61;&#39;&#39;)$result&#61;json_decode($result_str, true);return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: qqPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);return $response;}
}

 

4. [文件] 人人网 ~ 3KB

/*** PHP Library for renren.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class renrenPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope);return &#39;https://graph.renren.com/oauth/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://graph.renren.com/oauth/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://graph.renren.com/oauth/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();return $this->api(&#39;users.getInfo&#39;, $params, &#39;POST&#39;);}function setStatus($status){$params&#61;array(&#39;status&#39;&#61;>$status);return $this->api(&#39;status.set&#39;, $params, &#39;POST&#39;);}function getStatus($uid, $count&#61;10, $page&#61;1){$params&#61;array(&#39;uid&#39;&#61;>$uid,&#39;page&#39;&#61;>$page,&#39;count&#39;&#61;>$count);return $this->api(&#39;status.gets&#39;, $params, &#39;POST&#39;);}function addBlog($title, $content){$params&#61;array(&#39;title&#39;&#61;>$title,&#39;content&#39;&#61;>$content);return $this->api(&#39;blog.addBlog&#39;, $params, &#39;POST&#39;);}function getBlog($id, $uid){$params&#61;array(&#39;id&#39;&#61;>$id,&#39;uid&#39;&#61;>$uid);return $this->api(&#39;blog.get&#39;, $params, &#39;POST&#39;);}function getComments($id, $uid, $count&#61;10, $page&#61;1){$params&#61;array(&#39;id&#39;&#61;>$id,&#39;uid&#39;&#61;>$uid,&#39;page&#39;&#61;>$page,&#39;count&#39;&#61;>$count);return $this->api(&#39;blog.getComments&#39;, $params, &#39;POST&#39;);}function api($method_name, $params, $method&#61;&#39;GET&#39;){$params[&#39;method&#39;]&#61;$method_name;$params[&#39;v&#39;]&#61;&#39;1.0&#39;;$params[&#39;access_token&#39;]&#61;$this->access_token;$params[&#39;format&#39;]&#61;&#39;json&#39;;ksort($params);$sig_str&#61;&#39;&#39;;foreach($params as $k&#61;>$v)$sig_str.&#61;$k.&#39;&#61;&#39;.$v;$sig_str.&#61;$this->client_secret;$sig&#61;md5($sig_str);$params[&#39;sig&#39;]&#61;$sig;$url&#61;&#39;http://api.renren.com/restserver.do&#39;;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: renrenPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

5. [文件] 开心网 ~ 3KB

/*** PHP Library for kaixin001.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class kaixinPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope);return &#39;http://api.kaixin001.com/oauth2/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://api.kaixin001.com/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://api.kaixin001.com/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();$url&#61;&#39;https://api.kaixin001.com/users/me.json&#39;;return $this->api($url, $params);}function records_add($content, $picurl&#61;&#39;&#39;){$params&#61;array(&#39;content&#39;&#61;>$content);if($picurl!&#61;&#39;&#39;)$params[&#39;picurl&#39;]&#61;$picurl;$url&#61;&#39;https://api.kaixin001.com/records/add.json&#39;;return $this->api($url, $params, &#39;POST&#39;);}function records_me($num&#61;10, $start&#61;0){$params&#61;array(&#39;start&#39;&#61;>$start,&#39;num&#39;&#61;>$num);$url&#61;&#39;https://api.kaixin001.com/records/me.json&#39;;return $this->api($url, $params);}function comment_list($id, $uid, $num&#61;10, $start&#61;0){$params&#61;array(&#39;objtype&#39;&#61;>&#39;records&#39;,&#39;objid&#39;&#61;>$id,&#39;ouid&#39;&#61;>$uid,&#39;start&#39;&#61;>$start,&#39;num&#39;&#61;>$num);$url&#61;&#39;https://api.kaixin001.com/comment/list.json&#39;;return $this->api($url, $params);}function forward_list($id, $uid, $num&#61;10, $start&#61;0){$params&#61;array(&#39;objtype&#39;&#61;>&#39;records&#39;,&#39;objid&#39;&#61;>$id,&#39;ouid&#39;&#61;>$uid,&#39;start&#39;&#61;>$start,&#39;num&#39;&#61;>$num);$url&#61;&#39;https://api.kaixin001.com/forward/list.json&#39;;return $this->api($url, $params);}function like_show($id, $uid, $num&#61;10, $start&#61;0){$params&#61;array(&#39;objtype&#39;&#61;>&#39;records&#39;,&#39;objid&#39;&#61;>$id,&#39;ouid&#39;&#61;>$uid,&#39;start&#39;&#61;>$start,&#39;num&#39;&#61;>$num);$url&#61;&#39;https://api.kaixin001.com/like/show.json&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: kaixinPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

6. [文件] 网易微博 ~ 3KB

/*** PHP Library for t.163.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class t163PHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url);return &#39;https://api.t.163.com/oauth2/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://api.t.163.com/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://api.t.163.com/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();$url&#61;&#39;https://api.t.163.com/users/show.json&#39;;return $this->api($url, $params);}function user_timeline($id, $count&#61;10){$params&#61;array(&#39;user_id&#39;&#61;>$id,&#39;count&#39;&#61;>$count);$url&#61;&#39;https://api.t.163.com/statuses/user_timeline.json&#39;;return $this->api($url, $params);}function update($status){$params&#61;array(&#39;status&#39;&#61;>$status);$url&#61;&#39;https://api.t.163.com/statuses/update.json&#39;;return $this->api($url, $params, &#39;POST&#39;);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: t163PHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

7. [文件] 豆瓣 ~ 3KB

/*** PHP Library for douban.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class doubanPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope,&#39;state&#39;&#61;>md5(time()));return &#39;https://www.douban.com/service/auth2/auth?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://www.douban.com/service/auth2/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($callback_url, $refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://www.douban.com/service/auth2/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();$url&#61;&#39;https://api.douban.com/v2/user/~me&#39;;return $this->api($url, $params);}function share($text, $title, $url, $description&#61;&#39;&#39;, $pic&#61;&#39;&#39;){$params&#61;array(&#39;text&#39;&#61;>$text,&#39;rec_title&#39;&#61;>$title,&#39;rec_url&#39;&#61;>$url,&#39;rec_desc&#39;&#61;>$description,&#39;rec_image&#39;&#61;>$pic);$url&#61;&#39;https://api.douban.com/shuo/v2/statuses/&#39;;return $this->api($url, $params, &#39;POST&#39;);}function api($url, $params, $method&#61;&#39;GET&#39;){$headers[]&#61;"Authorization: Bearer ".$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params), &#39;&#39;, &#39;GET&#39;, $headers);}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;, $headers);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: doubanPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

8. [文件] 百度 ~ 2KB

/*** PHP Library for baidu.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class baiduPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope,&#39;state&#39;&#61;>md5(time()),&#39;display&#39;&#61;>&#39;page&#39;);return &#39;https://openapi.baidu.com/oauth/2.0/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://openapi.baidu.com/oauth/2.0/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://openapi.baidu.com/oauth/2.0/token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function user(){$params&#61;array();$url&#61;&#39;https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: baiduPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

9. [文件] Google ~ 2KB

/*** PHP Library for google.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class googlePHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope,&#39;state&#39;&#61;>&#39;profile&#39;,&#39;access_type&#39;&#61;>&#39;offline&#39;);return &#39;https://accounts.google.com/o/oauth2/auth?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://accounts.google.com/o/oauth2/token&#39;;$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);return $result;}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://accounts.google.com/o/oauth2/token&#39;;$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);return $result;}function me(){$params&#61;array();$url&#61;&#39;https://www.googleapis.com/oauth2/v1/userinfo&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$headers[]&#61;"Authorization: Bearer ".$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params), &#39;&#39;, &#39;GET&#39;, $headers);}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;, $headers);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: google(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

10. [文件] 微软 ~ 2KB

/*** PHP Library for live.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class livePHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope);return &#39;https://login.live.com/oauth20_authorize.srf?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://login.live.com/oauth20_token.srf&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;client_id&#39;&#61;>$this->client_id);$url&#61;&#39;https://login.live.com/oauth20_token.srf&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();$url&#61;&#39;https://apis.live.net/v5.0/me&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: livePHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

11. [文件] Instagram ~ 2KB

/*** PHP Library for instagram.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class instagramPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url);return &#39;https://api.instagram.com/oauth/authorize/?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://api.instagram.com/oauth/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}/**function access_token_refresh($refresh_token){}**/function user($id){$params&#61;array();$url&#61;&#39;https://api.instagram.com/v1/users/&#39;.$id.&#39;/&#39;;return $this->api($url, $params);}function user_media($id, $count&#61;10, $max_id&#61;&#39;&#39;){$params&#61;array(&#39;count&#39;&#61;>$count);if($max_id!&#61;&#39;&#39;)$params[&#39;max_id&#39;]&#61;$max_id;$url&#61;&#39;https://api.instagram.com/v1/users/&#39;.$id.&#39;/media/recent/&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: instagramPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

12. [文件] Facebook ~ 2KB

/*** PHP Library for facebook.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class facebookPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope);return &#39;https://graph.facebook.com/oauth/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://graph.facebook.com/oauth/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}/**function access_token_refresh($refresh_token){}**/function me(){$params&#61;array();$url&#61;&#39;https://graph.facebook.com/me&#39;;return $this->api($url, $params);}function my_feed($count&#61;10, $page&#61;1){$params&#61;array(&#39;page&#39;&#61;>$page,&#39;count&#39;&#61;>$count);$url&#61;&#39;https://graph.facebook.com/me/feed&#39;;return $this->api($url, $params);}function update($content){$params&#61;array(&#39;message&#39;&#61;>$content);$url&#61;&#39;https://graph.facebook.com/me/feed/&#39;;return $this->api($url, $params, &#39;POST&#39;);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: facebookPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

13. [文件] 360 ~ 2KB

/*** PHP Library for 360.cn** &#64;author PiscDong (http://www.piscdong.com/)*/
class o360PHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url){$params&#61;array(&#39;response_type&#39;&#61;>&#39;code&#39;,&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url);return &#39;https://openapi.360.cn/oauth2/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;authorization_code&#39;,&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://openapi.360.cn/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function access_token_refresh($refresh_token){$params&#61;array(&#39;grant_type&#39;&#61;>&#39;refresh_token&#39;,&#39;refresh_token&#39;&#61;>$refresh_token,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret);$url&#61;&#39;https://openapi.360.cn/oauth2/access_token&#39;;return $this->http($url, http_build_query($params), &#39;POST&#39;);}function me(){$params&#61;array();$url&#61;&#39;https://openapi.360.cn/user/me.json&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: o360PHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);$json_r&#61;array();if($response!&#61;&#39;&#39;)$json_r&#61;json_decode($response, true);return $json_r;}
}

 

14. [文件] github.php ~ 2KB

/*** PHP Library for github.com** &#64;author PiscDong (http://www.piscdong.com/)*/
class githubPHP
{function __construct($client_id, $client_secret, $access_token&#61;NULL){$this->client_id&#61;$client_id;$this->client_secret&#61;$client_secret;$this->access_token&#61;$access_token;}function login_url($callback_url, $scope&#61;&#39;&#39;){$params&#61;array(&#39;client_id&#39;&#61;>$this->client_id,&#39;redirect_uri&#39;&#61;>$callback_url,&#39;scope&#39;&#61;>$scope);return &#39;https://github.com/login/oauth/authorize?&#39;.http_build_query($params);}function access_token($callback_url, $code){$params&#61;array(&#39;code&#39;&#61;>$code,&#39;client_id&#39;&#61;>$this->client_id,&#39;client_secret&#39;&#61;>$this->client_secret,&#39;redirect_uri&#39;&#61;>$callback_url);$url&#61;&#39;https://github.com/login/oauth/access_token&#39;;$result_str&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);$json_r&#61;array();if($result_str!&#61;&#39;&#39;)parse_str($result_str, $json_r);return $json_r;}/**function access_token_refresh($refresh_token){}**/function me(){$params&#61;array();$url&#61;&#39;https://api.github.com/user&#39;;return $this->api($url, $params);}function api($url, $params, $method&#61;&#39;GET&#39;){$params[&#39;access_token&#39;]&#61;$this->access_token;if($method&#61;&#61;&#39;GET&#39;){$result_str&#61;$this->http($url.&#39;?&#39;.http_build_query($params));}else{$result_str&#61;$this->http($url, http_build_query($params), &#39;POST&#39;);}$result&#61;array();if($result_str!&#61;&#39;&#39;)$result&#61;json_decode($result_str, true);return $result;}function http($url, $postfields&#61;&#39;&#39;, $method&#61;&#39;GET&#39;, $headers&#61;array()){$ci&#61;curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method&#61;&#61;&#39;POST&#39;){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!&#61;&#39;&#39;)curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]&#61;"User-Agent: githubPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response&#61;curl_exec($ci);curl_close($ci);return $response;}
}

 

15. [代码]示例文件&#xff0c;以新浪微博为例&#xff0c;其他平台方法类似

/*** 示例文件&#xff0c;以新浪微博为例&#xff0c;其他平台方法类似*///生成登录链接
require_once(&#39;sina.php&#39;);
$app_key&#61;&#39;&#39;; //新浪微博应用App Key
$app_secret&#61;&#39;&#39;; //新浪微博应用App Secret
$callback_url&#61;&#39;http://yoururl/sina_callback.php&#39;; //回调网址&#xff0c;请根据自己的实际情况修改$sina&#61;new sinaPHP($app_key, $app_secret);
$login_url&#61;$sina->login_url($callback_url); //生成登录链接&#xff0c;部分平台需要权限&#xff0c;格式请参考各平台api文档
echo &#39;点击进入授权页面&#39;;//授权回调页面&#xff0c;即生成登录链接时的$callback_url
require_once(&#39;sina.php&#39;);
$app_key&#61;&#39;&#39;; //新浪微博应用App Key
$app_secret&#61;&#39;&#39;; //新浪微博应用App Secret
$callback_url&#61;&#39;http://yoururl/sina_callback.php&#39;; //回调网址&#xff0c;必须和生成登录链接时相同if(isset($_GET[&#39;code&#39;]) && $_GET[&#39;code&#39;]!&#61;&#39;&#39;){$sina&#61;new sinaPHP($app_key, $app_secret);$result&#61;$sina->access_token($callback_url, $_GET[&#39;code&#39;]); //获取access token/*** $result[&#39;access_token&#39;]&#xff0c;用户access token* $result[&#39;expires_in&#39;]&#xff0c;access token的有效期&#xff0c;单位&#xff1a;秒* 部分平台会有$result[&#39;refresh_token&#39;]&#xff0c;refresh token&#xff0c;access token到期后使用refresh token生成新的access token* 腾讯微博还需要保存$_GET[&#39;openid&#39;]*/
}//用户登录授权后操作api
require_once(&#39;sina.php&#39;);
$app_key&#61;&#39;&#39;; //新浪微博应用App Key
$app_secret&#61;&#39;&#39;; //新浪微博应用App Secret
$access_token&#61;&#39;&#39;; //授权回调页面生成的用户access token$sina&#61;new sinaPHP($app_key, $app_secret, $access_token); //腾讯微博还需要openid&#xff0c;授权回调页面保存的$_GET[&#39;openid&#39;]$sina_uid&#61;$sina->get_uid(); //登录用户uid
//其他功能请参考sina.php自行使用&#xff0c;或者根据api文档自行添加
//其他平台的使用方法和新浪微博类似&#xff0c;各种api的返回数据格式各有不同&#xff0c;请自行参考各平台的api文档//支持refresh token的平台在access token到期后请使用access_token_refresh()生成新的access token

 

来源&#xff1a;http://www.oschina.net/code/snippet_930167_16877#28044

 

 

 



推荐阅读
  • 开发笔记:Python之路第一篇:初识Python
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Python之路第一篇:初识Python相关的知识,希望对你有一定的参考价值。Python简介& ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • MACElasticsearch安装步骤及验证方法
    本文介绍了MACElasticsearch的安装步骤,包括下载ZIP文件、解压到安装目录、启动服务,并提供了验证启动是否成功的方法。同时,还介绍了安装elasticsearch-head插件的方法,以便于进行查询操作。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • Sleuth+zipkin链路追踪SpringCloud微服务的解决方案
    在庞大的微服务群中,随着业务扩展,微服务个数增多,系统调用链路复杂化。Sleuth+zipkin是解决SpringCloud微服务定位和追踪的方案。通过TraceId将不同服务调用的日志串联起来,实现请求链路跟踪。通过Feign调用和Request传递TraceId,将整个调用链路的服务日志归组合并,提供定位和追踪的功能。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
author-avatar
手机用户2502856573
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有