1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268 |
- <?php
- /**
- * PHP SDK for weibo.com (using OAuth2)
- *
- * @author Elmer Zhang <freeboy6716@gmail.com>
- */
- /**
- * @ignore
- */
- class OAuthException extends Exception {
- // pass
- }
- /**
- * 新浪微博 OAuth 认证类(OAuth2)
- *
- * 授权机制说明请大家参考微博开放平台文档:{@link http://open.weibo.com/wiki/Oauth2}
- *
- * @package sae
- * @author Elmer Zhang
- * @version 1.0
- */
- class SaeTOAuthV2 {
- /**
- * @ignore
- */
- public $client_id;
- /**
- * @ignore
- */
- public $client_secret;
- /**
- * @ignore
- */
- public $access_token;
- /**
- * @ignore
- */
- public $refresh_token;
- /**
- * Contains the last HTTP status code returned.
- *
- * @ignore
- */
- public $http_code;
- /**
- * Contains the last API call.
- *
- * @ignore
- */
- public $url;
- /**
- * Set up the API root URL.
- *
- * @ignore
- */
- public $host = "https://api.weibo.com/2/";
- /**
- * Set timeout default.
- *
- * @ignore
- */
- public $timeout = 30;
- /**
- * Set connect timeout.
- *
- * @ignore
- */
- public $connecttimeout = 30;
- /**
- * Verify SSL Cert.
- *
- * @ignore
- */
- public $ssl_verifypeer = FALSE;
- /**
- * Respons format.
- *
- * @ignore
- */
- public $format = 'json';
- /**
- * Decode returned json data.
- *
- * @ignore
- */
- public $decode_json = TRUE;
- /**
- * Contains the last HTTP headers returned.
- *
- * @ignore
- */
- public $http_info;
- /**
- * Set the useragnet.
- *
- * @ignore
- */
- public $useragent = 'Sae T OAuth2 v0.1';
- /**
- * print the debug info
- *
- * @ignore
- */
- public $debug = FALSE;
- /**
- * boundary of multipart
- * @ignore
- */
- public static $boundary = '';
- /**
- * Set API URLS
- */
- /**
- * @ignore
- */
- function accessTokenURL() { return 'https://api.weibo.com/oauth2/access_token'; }
- /**
- * @ignore
- */
- function authorizeURL() { return 'https://api.weibo.com/oauth2/authorize'; }
- /**
- * construct WeiboOAuth object
- */
- function __construct($client_id, $client_secret, $access_token = NULL, $refresh_token = NULL) {
- $this->client_id = $client_id;
- $this->client_secret = $client_secret;
- $this->access_token = $access_token;
- $this->refresh_token = $refresh_token;
- }
- /**
- * authorize接口
- *
- * 对应API:{@link http://open.weibo.com/wiki/Oauth2/authorize Oauth2/authorize}
- *
- * @param string $url 授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址
- * @param string $response_type 支持的值包括 code 和token 默认值为code
- * @param string $state 用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数
- * @param string $display 授权页面类型 可选范围:
- * - default 默认授权页面
- * - mobile 支持html5的手机
- * - popup 弹窗授权页
- * - wap1.2 wap1.2页面
- * - wap2.0 wap2.0页面
- * - js js-sdk 专用 授权页面是弹窗,返回结果为js-sdk回掉函数
- * - apponweibo 站内应用专用,站内应用不传display参数,并且response_type为token时,默认使用改display.授权后不会返回access_token,只是输出js刷新站内应用父框架
- * @return array
- */
- function getAuthorizeURL( $url, $response_type = 'code', $state = NULL, $display = NULL ) {
- $params = array();
- $params['client_id'] = $this->client_id;
- $params['redirect_uri'] = $url;
- $params['response_type'] = $response_type;
- $params['state'] = $state;
- $params['display'] = $display;
- return $this->authorizeURL() . "?" . http_build_query($params);
- }
- /**
- * access_token接口
- *
- * 对应API:{@link http://open.weibo.com/wiki/OAuth2/access_token OAuth2/access_token}
- *
- * @param string $type 请求的类型,可以为:code, password, token
- * @param array $keys 其他参数:
- * - 当$type为code时: array('code'=>..., 'redirect_uri'=>...)
- * - 当$type为password时: array('username'=>..., 'password'=>...)
- * - 当$type为token时: array('refresh_token'=>...)
- * @return array
- */
- function getAccessToken( $type = 'code', $keys ) {
- $params = array();
- $params['client_id'] = $this->client_id;
- $params['client_secret'] = $this->client_secret;
- if ( $type === 'token' ) {
- $params['grant_type'] = 'refresh_token';
- $params['refresh_token'] = $keys['refresh_token'];
- } elseif ( $type === 'code' ) {
- $params['grant_type'] = 'authorization_code';
- $params['code'] = $keys['code'];
- $params['redirect_uri'] = $keys['redirect_uri'];
- } elseif ( $type === 'password' ) {
- $params['grant_type'] = 'password';
- $params['username'] = $keys['username'];
- $params['password'] = $keys['password'];
- } else {
- throw new OAuthException("wrong auth type");
- }
- $response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params);
- $token = json_decode($response, true);
- if ( is_array($token) && !isset($token['error']) ) {
- $this->access_token = $token['access_token'];
- //$this->refresh_token = $token['refresh_token'];
- } else {
- throw new OAuthException("get access token failed." . $token['error']);
- }
- return $token;
- }
- /**
- * 解析 signed_request
- *
- * @param string $signed_request 应用框架在加载iframe时会通过向Canvas URL post的参数signed_request
- *
- * @return array
- */
- function parseSignedRequest($signed_request) {
- list($encoded_sig, $payload) = explode('.', $signed_request, 2);
- $sig = self::base64decode($encoded_sig) ;
- $data = json_decode(self::base64decode($payload), true);
- if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') return '-1';
- $expected_sig = hash_hmac('sha256', $payload, $this->client_secret, true);
- return ($sig !== $expected_sig)? '-2':$data;
- }
- /**
- * @ignore
- */
- function base64decode($str) {
- return base64_decode(strtr($str.str_repeat('=', (4 - strlen($str) % 4)), '-_', '+/'));
- }
- /**
- * 读取jssdk授权信息,用于和jssdk的同步登录
- *
- * @return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false
- */
- function getTokenFromJSSDK() {
- $key = "weibojs_" . $this->client_id;
- if ( isset($_COOKIE[$key]) && $cookie = $_COOKIE[$key] ) {
- parse_str($cookie, $token);
- if ( isset($token['access_token']) && isset($token['refresh_token']) ) {
- $this->access_token = $token['access_token'];
- $this->refresh_token = $token['refresh_token'];
- return $token;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- /**
- * 从数组中读取access_token和refresh_token
- * 常用于从Session或Cookie中读取token,或通过Session/Cookie中是否存有token判断登录状态。
- *
- * @param array $arr 存有access_token和secret_token的数组
- * @return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false
- */
- function getTokenFromArray( $arr ) {
- if (isset($arr['access_token']) && $arr['access_token']) {
- $token = array();
- $this->access_token = $token['access_token'] = $arr['access_token'];
- if (isset($arr['refresh_token']) && $arr['refresh_token']) {
- $this->refresh_token = $token['refresh_token'] = $arr['refresh_token'];
- }
- return $token;
- } else {
- return false;
- }
- }
- /**
- * GET wrappwer for oAuthRequest.
- *
- * @return mixed
- */
- function get($url, $parameters = array()) {
- $response = $this->oAuthRequest($url, 'GET', $parameters);
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
- /**
- * POST wreapper for oAuthRequest.
- *
- * @return mixed
- */
- function post($url, $parameters = array(), $multi = false) {
- $response = $this->oAuthRequest($url, 'POST', $parameters, $multi );
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
- /**
- * DELTE wrapper for oAuthReqeust.
- *
- * @return mixed
- */
- function delete($url, $parameters = array()) {
- $response = $this->oAuthRequest($url, 'DELETE', $parameters);
- if ($this->format === 'json' && $this->decode_json) {
- return json_decode($response, true);
- }
- return $response;
- }
- /**
- * Format and sign an OAuth / API request
- *
- * @return string
- * @ignore
- */
- function oAuthRequest($url, $method, $parameters, $multi = false) {
- if (strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0) {
- $url = "{$this->host}{$url}.{$this->format}";
- }
- switch ($method) {
- case 'GET':
- $url = $url . '?' . http_build_query($parameters);
- return $this->http($url, 'GET');
- default:
- $headers = array();
- if (!$multi && (is_array($parameters) || is_object($parameters)) ) {
- $body = http_build_query($parameters);
- } else {
- $body = self::build_http_query_multi($parameters);
- $headers[] = "Content-Type: multipart/form-data; boundary=" . self::$boundary;
- }
- return $this->http($url, $method, $body, $headers);
- }
- }
- /**
- * Make an HTTP request
- *
- * @return string API results
- * @ignore
- */
- function http($url, $method, $postfields = NULL, $headers = array()) {
- $this->http_info = array();
- $ci = curl_init();
- /* Curl settings */
- curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
- curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
- curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ci, CURLOPT_ENCODING, "");
- curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
- curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, 1);
- curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
- curl_setopt($ci, CURLOPT_HEADER, FALSE);
- switch ($method) {
- case 'POST':
- curl_setopt($ci, CURLOPT_POST, TRUE);
- if (!empty($postfields)) {
- curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
- $this->postdata = $postfields;
- }
- break;
- case 'DELETE':
- curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
- if (!empty($postfields)) {
- $url = "{$url}?{$postfields}";
- }
- }
- if ( isset($this->access_token) && $this->access_token )
- $headers[] = "Authorization: OAuth2 ".$this->access_token;
- if ( !empty($this->remote_ip) ) {
- if ( defined('SAE_ACCESSKEY') ) {
- $headers[] = "SaeRemoteIP: " . $this->remote_ip;
- } else {
- $headers[] = "API-RemoteIP: " . $this->remote_ip;
- }
- } else {
- if ( !defined('SAE_ACCESSKEY') ) {
- $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR'];
- }
- }
- curl_setopt($ci, CURLOPT_URL, $url );
- curl_setopt($ci, CURLOPT_HTTPHEADER, $headers );
- curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE );
- $response = curl_exec($ci);
- $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
- $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
- $this->url = $url;
- if ($this->debug) {
- echo "=====post data======\r\n";
- var_dump($postfields);
- echo "=====headers======\r\n";
- print_r($headers);
- echo '=====request info====='."\r\n";
- print_r( curl_getinfo($ci) );
- echo '=====response====='."\r\n";
- print_r( $response );
- }
- curl_close ($ci);
- return $response;
- }
- /**
- * Get the header info to store.
- *
- * @return int
- * @ignore
- */
- function getHeader($ch, $header) {
- $i = strpos($header, ':');
- if (!empty($i)) {
- $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
- $value = trim(substr($header, $i + 2));
- $this->http_header[$key] = $value;
- }
- return strlen($header);
- }
- /**
- * @ignore
- */
- public static function build_http_query_multi($params) {
- if (!$params) return '';
- uksort($params, 'strcmp');
- $pairs = array();
- self::$boundary = $boundary = uniqid('------------------');
- $MPboundary = '--'.$boundary;
- $endMPboundary = $MPboundary. '--';
- $multipartbody = '';
- foreach ($params as $parameter => $value) {
- if( in_array($parameter, array('pic', 'image')) && $value{0} == '@' ) {
- $url = ltrim( $value, '@' );
- $content = file_get_contents( $url );
- $array = explode( '?', basename( $url ) );
- $filename = $array[0];
- $multipartbody .= $MPboundary . "\r\n";
- $multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"'. "\r\n";
- $multipartbody .= "Content-Type: image/unknown\r\n\r\n";
- $multipartbody .= $content. "\r\n";
- } else {
- $multipartbody .= $MPboundary . "\r\n";
- $multipartbody .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n";
- $multipartbody .= $value."\r\n";
- }
- }
- $multipartbody .= $endMPboundary;
- return $multipartbody;
- }
- }
- /**
- * 新浪微博操作类V2
- *
- * 使用前需要先手工调用saetv2.ex.class.php <br />
- *
- * @package sae
- * @author Easy Chen, Elmer Zhang,Lazypeople
- * @version 1.0
- */
- class SaeTClientV2
- {
- /**
- * 构造函数
- *
- * @access public
- * @param mixed $akey 微博开放平台应用APP KEY
- * @param mixed $skey 微博开放平台应用APP SECRET
- * @param mixed $access_token OAuth认证返回的token
- * @param mixed $refresh_token OAuth认证返回的token secret
- * @return void
- */
- function __construct( $akey, $skey, $access_token, $refresh_token = NULL)
- {
- $this->oauth = new SaeTOAuthV2( $akey, $skey, $access_token, $refresh_token );
- }
- /**
- * 开启调试信息
- *
- * 开启调试信息后,SDK会将每次请求微博API所发送的POST Data、Headers以及请求信息、返回内容输出出来。
- *
- * @access public
- * @param bool $enable 是否开启调试信息
- * @return void
- */
- function set_debug( $enable )
- {
- $this->oauth->debug = $enable;
- }
- /**
- * 设置用户IP
- *
- * SDK默认将会通过$_SERVER['REMOTE_ADDR']获取用户IP,在请求微博API时将用户IP附加到Request Header中。但某些情况下$_SERVER['REMOTE_ADDR']取到的IP并非用户IP,而是一个固定的IP(例如使用SAE的Cron或TaskQueue服务时),此时就有可能会造成该固定IP达到微博API调用频率限额,导致API调用失败。此时可使用本方法设置用户IP,以避免此问题。
- *
- * @access public
- * @param string $ip 用户IP
- * @return bool IP为非法IP字符串时,返回false,否则返回true
- */
- function set_remote_ip( $ip )
- {
- if ( ip2long($ip) !== false ) {
- $this->oauth->remote_ip = $ip;
- return true;
- } else {
- return false;
- }
- }
- /**
- * 获取最新的公共微博消息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/public_timeline statuses/public_timeline}
- *
- * @access public
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @return array
- */
- function public_timeline( $page = 1, $count = 50, $base_app = 0 )
- {
- $params = array();
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['base_app'] = intval($base_app);
- return $this->oauth->get('statuses/public_timeline', $params);//可能是接口的bug不能补全
- }
- /**
- * 获取当前登录用户及其所关注用户的最新微博消息。
- *
- * 获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。同friends_timeline()
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/home_timeline statuses/home_timeline}
- *
- * @access public
- * @param int $page 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。默认值1。可选。
- * @param int $count 每次返回的记录数。缺省值50,最大值200。可选。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的微博消息。可选。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
- * @return array
- */
- function home_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $base_app = 0, $feature = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['base_app'] = intval($base_app);
- $params['feature'] = intval($feature);
- return $this->oauth->get('statuses/home_timeline', $params);
- }
- /**
- * 获取当前登录用户及其所关注用户的最新微博消息。
- *
- * 获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。同home_timeline()
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/friends_timeline statuses/friends_timeline}
- *
- * @access public
- * @param int $page 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。默认值1。可选。
- * @param int $count 每次返回的记录数。缺省值50,最大值200。可选。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的微博消息。可选。
- * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。可选。
- * @param int $feature 微博类型,0全部,1原创,2图片,3视频,4音乐. 返回指定类型的微博信息内容。转为为0。可选。
- * @return array
- */
- function friends_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $base_app = 0, $feature = 0 )
- {
- return $this->home_timeline( $since_id, $max_id, $count, $page, $base_app, $feature);
- }
- /**
- * 获取用户发布的微博信息列表
- *
- * 返回用户的发布的最近n条信息,和用户微博页面返回内容是一致的。此接口也可以请求其他用户的最新发表微博。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/user_timeline statuses/user_timeline}
- *
- * @access public
- * @param int $page 页码
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。
- * @param mixed $uid 指定用户UID或微博昵称
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。
- * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。
- * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
- * @param int $trim_user 返回值中user信息开关,0:返回完整的user信息、1:user字段仅返回uid,默认为0。
- * @return array
- */
- function user_timeline_by_id( $uid = NULL , $page = 1 , $count = 50 , $since_id = 0, $max_id = 0, $feature = 0, $trim_user = 0, $base_app = 0)
- {
- $params = array();
- $params['uid']=$uid;
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['base_app'] = intval($base_app);
- $params['feature'] = intval($feature);
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['trim_user'] = intval($trim_user);
- return $this->oauth->get( 'statuses/user_timeline', $params );
- }
-
-
- /**
- * 获取用户发布的微博信息列表
- *
- * 返回用户的发布的最近n条信息,和用户微博页面返回内容是一致的。此接口也可以请求其他用户的最新发表微博。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/user_timeline statuses/user_timeline}
- *
- * @access public
- * @param string $screen_name 微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数
- * @param int $page 页码
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。
- * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
- * @param int $trim_user 返回值中user信息开关,0:返回完整的user信息、1:user字段仅返回uid,默认为0。
- * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。
- * @return array
- */
- function user_timeline_by_name( $screen_name = NULL , $page = 1 , $count = 50 , $since_id = 0, $max_id = 0, $feature = 0, $trim_user = 0, $base_app = 0 )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['base_app'] = intval($base_app);
- $params['feature'] = intval($feature);
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['trim_user'] = intval($trim_user);
- return $this->oauth->get( 'statuses/user_timeline', $params );
- }
-
-
-
- /**
- * 批量获取指定的一批用户的timeline
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/timeline_batch statuses/timeline_batch}
- *
- * @param string $screen_name 需要查询的用户昵称,用半角逗号分隔,一次最多20个
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
- * @return array
- */
- function timeline_batch_by_name( $screen_name, $page = 1, $count = 50, $feature = 0, $base_app = 0)
- {
- $params = array();
- if (is_array($screen_name) && !empty($screen_name)) {
- $params['screen_name'] = join(',', $screen_name);
- } else {
- $params['screen_name'] = $screen_name;
- }
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['base_app'] = intval($base_app);
- $params['feature'] = intval($feature);
- return $this->oauth->get('statuses/timeline_batch', $params);
- }
- /**
- * 批量获取指定的一批用户的timeline
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/timeline_batch statuses/timeline_batch}
- *
- * @param string $uids 需要查询的用户ID,用半角逗号分隔,一次最多20个。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
- * @return array
- */
- function timeline_batch_by_id( $uids, $page = 1, $count = 50, $feature = 0, $base_app = 0)
- {
- $params = array();
- if (is_array($uids) && !empty($uids)) {
- foreach($uids as $k => $v) {
- $this->id_format($uids[$k]);
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- $params['count'] = intval($count);
- $params['page'] = intval($page);
- $params['base_app'] = intval($base_app);
- $params['feature'] = intval($feature);
- return $this->oauth->get('statuses/timeline_batch', $params);
- }
- /**
- * 返回一条原创微博消息的最新n条转发微博消息。本接口无法对非原创微博进行查询。
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/repost_timeline statuses/repost_timeline}
- *
- * @access public
- * @param int $sid 要获取转发微博列表的原创微博ID。
- * @param int $page 返回结果的页码。
- * @param int $count 单页返回的最大记录数,最多返回200条,默认50。可选。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的记录(比since_id发表时间晚)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的记录。可选。
- * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
- * @return array
- */
- function repost_timeline( $sid, $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0 )
- {
- $this->id_format($sid);
- $params = array();
- $params['id'] = $sid;
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['filter_by_author'] = intval($filter_by_author);
- return $this->request_with_pager( 'statuses/repost_timeline', $page, $count, $params );
- }
- /**
- * 获取当前用户最新转发的n条微博消息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/repost_by_me statuses/repost_by_me}
- *
- * @access public
- * @param int $page 返回结果的页码。
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。可选。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的记录(比since_id发表时间晚)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的记录。可选。
- * @return array
- */
- function repost_by_me( $page = 1, $count = 50, $since_id = 0, $max_id = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- return $this->request_with_pager('statuses/repost_by_me', $page, $count, $params );
- }
- /**
- * 获取@当前用户的微博列表
- *
- * 返回最新n条提到登录用户的微博消息(即包含@username的微博消息)
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/mentions statuses/mentions}
- *
- * @access public
- * @param int $page 返回结果的页序号。
- * @param int $count 每次返回的最大记录数(即页面大小),不大于200,默认为50。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。
- * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
- * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。
- * @param int $filter_by_type 原创筛选类型,0:全部微博、1:原创的微博,默认为0。
- * @return array
- */
- function mentions( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0, $filter_by_type = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['filter_by_author'] = $filter_by_author;
- $params['filter_by_source'] = $filter_by_source;
- $params['filter_by_type'] = $filter_by_type;
- return $this->request_with_pager( 'statuses/mentions', $page, $count, $params );
- }
- /**
- * 根据ID获取单条微博信息内容
- *
- * 获取单条ID的微博信息,作者信息将同时返回。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/show statuses/show}
- *
- * @access public
- * @param int $id 要获取已发表的微博ID, 如ID不存在返回空
- * @return array
- */
- function show_status( $id )
- {
- $this->id_format($id);
- $params = array();
- $params['id'] = $id;
- return $this->oauth->get('statuses/show', $params);
- }
- /**
- * 根据微博id号获取微博的信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/show_batch statuses/show_batch}
- *
- * @param string $ids 需要查询的微博ID,用半角逗号分隔,最多不超过50个。
- * @return array
- */
- function show_batch( $ids )
- {
- $params=array();
- if (is_array($ids) && !empty($ids)) {
- foreach($ids as $k => $v) {
- $this->id_format($ids[$k]);
- }
- $params['ids'] = join(',', $ids);
- } else {
- $params['ids'] = $ids;
- }
- return $this->oauth->get('statuses/show_batch', $params);
- }
- /**
- * 通过微博(评论、私信)ID获取其MID
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/querymid statuses/querymid}
- *
- * @param int|string $id 需要查询的微博(评论、私信)ID,批量模式下,用半角逗号分隔,最多不超过20个。
- * @param int $type 获取类型,1:微博、2:评论、3:私信,默认为1。
- * @param int $is_batch 是否使用批量模式,0:否、1:是,默认为0。
- * @return array
- */
- function querymid( $id, $type = 1, $is_batch = 0 )
- {
- $params = array();
- $params['id'] = $id;
- $params['type'] = intval($type);
- $params['is_batch'] = intval($is_batch);
- return $this->oauth->get( 'statuses/querymid', $params);
- }
- /**
- * 通过微博(评论、私信)MID获取其ID
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/queryid statuses/queryid}
- *
- * @param int|string $mid 需要查询的微博(评论、私信)MID,批量模式下,用半角逗号分隔,最多不超过20个。
- * @param int $type 获取类型,1:微博、2:评论、3:私信,默认为1。
- * @param int $is_batch 是否使用批量模式,0:否、1:是,默认为0。
- * @param int $inbox 仅对私信有效,当MID类型为私信时用此参数,0:发件箱、1:收件箱,默认为0 。
- * @param int $isBase62 MID是否是base62编码,0:否、1:是,默认为0。
- * @return array
- */
- function queryid( $mid, $type = 1, $is_batch = 0, $inbox = 0, $isBase62 = 0)
- {
- $params = array();
- $params['mid'] = $mid;
- $params['type'] = intval($type);
- $params['is_batch'] = intval($is_batch);
- $params['inbox'] = intval($inbox);
- $params['isBase62'] = intval($isBase62);
- return $this->oauth->get('statuses/queryid', $params);
- }
- /**
- * 按天返回热门微博转发榜的微博列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/repost_daily statuses/hot/repost_daily}
- *
- * @param int $count 返回的记录条数,最大不超过50,默认为20。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @return array
- */
- function repost_daily( $count = 20, $base_app = 0)
- {
- $params = array();
- $params['count'] = intval($count);
- $params['base_app'] = intval($base_app);
- return $this->oauth->get('statuses/hot/repost_daily', $params);
- }
- /**
- * 按周返回热门微博转发榜的微博列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/repost_weekly statuses/hot/repost_weekly}
- *
- * @param int $count 返回的记录条数,最大不超过50,默认为20。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @return array
- */
- function repost_weekly( $count = 20, $base_app = 0)
- {
- $params = array();
- $params['count'] = intval($count);
- $params['base_app'] = intval($base_app);
- return $this->oauth->get( 'statuses/hot/repost_weekly', $params);
- }
- /**
- * 按天返回热门微博评论榜的微博列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/comments_daily statuses/hot/comments_daily}
- *
- * @param int $count 返回的记录条数,最大不超过50,默认为20。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @return array
- */
- function comments_daily( $count = 20, $base_app = 0)
- {
- $params = array();
- $params['count'] = intval($count);
- $params['base_app'] = intval($base_app);
- return $this->oauth->get( 'statuses/hot/comments_daily', $params);
- }
- /**
- * 按周返回热门微博评论榜的微博列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/comments_weekly statuses/hot/comments_weekly}
- *
- * @param int $count 返回的记录条数,最大不超过50,默认为20。
- * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * @return array
- */
- function comments_weekly( $count = 20, $base_app = 0)
- {
- $params = array();
- $params['count'] = intval($count);
- $params['base_app'] = intval($base_app);
- return $this->oauth->get( 'statuses/hot/comments_weekly', $params);
- }
- /**
- * 转发一条微博信息。
- *
- * 可加评论。为防止重复,发布的信息与最新信息一样话,将会被忽略。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/repost statuses/repost}
- *
- * @access public
- * @param int $sid 转发的微博ID
- * @param string $text 添加的评论信息。可选。
- * @param int $is_comment 是否在转发的同时发表评论,0:否、1:评论给当前微博、2:评论给原微博、3:都评论,默认为0。
- * @return array
- */
- function repost( $sid, $text = NULL, $is_comment = 0 )
- {
- $this->id_format($sid);
- $params = array();
- $params['id'] = $sid;
- $params['is_comment'] = $is_comment;
- if( $text ) $params['status'] = $text;
- return $this->oauth->post( 'statuses/repost', $params );
- }
- /**
- * 删除一条微博
- *
- * 根据ID删除微博消息。注意:只能删除自己发布的信息。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/destroy statuses/destroy}
- *
- * @access public
- * @param int $id 要删除的微博ID
- * @return array
- */
- function delete( $id )
- {
- return $this->destroy( $id );
- }
- /**
- * 删除一条微博
- *
- * 删除微博。注意:只能删除自己发布的信息。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/destroy statuses/destroy}
- *
- * @access public
- * @param int $id 要删除的微博ID
- * @return array
- */
- function destroy( $id )
- {
- $this->id_format($id);
- $params = array();
- $params['id'] = $id;
- return $this->oauth->post( 'statuses/destroy', $params );
- }
-
- /**
- * 发表微博
- *
- * 发布一条微博信息。
- * <br />注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。
- * <br />注意:为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/update statuses/update}
- *
- * @access public
- * @param string $status 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。
- * @param float $lat 纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。可选。
- * @param float $long 经度。有效范围-180.0到+180.0, +表示东经。可选。
- * @param mixed $annotations 可选参数。元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。每条微博可以包含一个或者多个元数据。请以json字串的形式提交,字串长度不超过512个字符,或者数组方式,要求json_encode后字串长度不超过512个字符。具体内容可以自定。例如:'[{"type2":123}, {"a":"b", "c":"d"}]'或array(array("type2"=>123), array("a"=>"b", "c"=>"d"))。
- * @return array
- */
- function update( $status, $lat = NULL, $long = NULL, $annotations = NULL )
- {
- $params = array();
- $params['status'] = $status;
- if ($lat) {
- $params['lat'] = floatval($lat);
- }
- if ($long) {
- $params['long'] = floatval($long);
- }
- if (is_string($annotations)) {
- $params['annotations'] = $annotations;
- } elseif (is_array($annotations)) {
- $params['annotations'] = json_encode($annotations);
- }
- return $this->oauth->post( 'statuses/update', $params );
- }
- /**
- * 发表图片微博
- *
- * 发表图片微博消息。目前上传图片大小限制为<5M。
- * <br />注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/upload statuses/upload}
- *
- * @access public
- * @param string $status 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。
- * @param string $pic_path 要发布的图片路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法]
- * @param float $lat 纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。可选。
- * @param float $long 可选参数,经度。有效范围-180.0到+180.0, +表示东经。可选。
- * @return array
- */
- function upload( $status, $pic_path, $lat = NULL, $long = NULL )
- {
- $params = array();
- $params['status'] = $status;
- $params['pic'] = '@'.$pic_path;
- if ($lat) {
- $params['lat'] = floatval($lat);
- }
- if ($long) {
- $params['long'] = floatval($long);
- }
- return $this->oauth->post( 'statuses/upload', $params, true );
- }
- /**
- * 指定一个图片URL地址抓取后上传并同时发布一条新微博
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/statuses/upload_url_text statuses/upload_url_text}
- *
- * @param string $status 要发布的微博文本内容,内容不超过140个汉字。
- * @param string $url 图片的URL地址,必须以http开头。
- * @return array
- */
- function upload_url_text( $status, $url )
- {
- $params = array();
- $params['status'] = $status;
- $params['url'] = $url;
- return $this->oauth->post( 'statuses/upload', $params, true );
- }
- /**
- * 获取表情列表
- *
- * 返回新浪微博官方所有表情、魔法表情的相关信息。包括短语、表情类型、表情分类,是否热门等。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/emotions emotions}
- *
- * @access public
- * @param string $type 表情类别。"face":普通表情,"ani":魔法表情,"cartoon":动漫表情。默认为"face"。可选。
- * @param string $language 语言类别,"cnname"简体,"twname"繁体。默认为"cnname"。可选
- * @return array
- */
- function emotions( $type = "face", $language = "cnname" )
- {
- $params = array();
- $params['type'] = $type;
- $params['language'] = $language;
- return $this->oauth->get( 'emotions', $params );
- }
- /**
- * 根据微博ID返回某条微博的评论列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/show comments/show}
- *
- * @param int $sid 需要查询的微博ID。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。
- * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
- * @return array
- */
- function get_comments_by_sid( $sid, $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0 )
- {
- $params = array();
- $this->id_format($sid);
- $params['id'] = $sid;
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['count'] = $count;
- $params['page'] = $page;
- $params['filter_by_author'] = $filter_by_author;
- return $this->oauth->get( 'comments/show', $params );
- }
- /**
- * 获取当前登录用户所发出的评论列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/by_me comments/by_me}
- *
- * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。
- * @return array
- */
- function comments_by_me( $page = 1 , $count = 50, $since_id = 0, $max_id = 0, $filter_by_source = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['count'] = $count;
- $params['page'] = $page;
- $params['filter_by_source'] = $filter_by_source;
- return $this->oauth->get( 'comments/by_me', $params );
- }
- /**
- * 获取当前登录用户所接收到的评论列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/to_me comments/to_me}
- *
- * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
- * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。
- * @return array
- */
- function comments_to_me( $page = 1 , $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0)
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['count'] = $count;
- $params['page'] = $page;
- $params['filter_by_author'] = $filter_by_author;
- $params['filter_by_source'] = $filter_by_source;
- return $this->oauth->get( 'comments/to_me', $params );
- }
- /**
- * 最新评论(按时间)
- *
- * 返回最新n条发送及收到的评论。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/comments/timeline comments/timeline}
- *
- * @access public
- * @param int $page 页码
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。
- * @param int $since_id 若指定此参数,则只返回ID比since_id大的评论(比since_id发表时间晚)。可选。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论。可选。
- * @return array
- */
- function comments_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- return $this->request_with_pager( 'comments/timeline', $page, $count, $params );
- }
- /**
- * 获取最新的提到当前登录用户的评论,即@我的评论
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/mentions comments/mentions}
- *
- * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
- * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。
- * @return array
- */
- function comments_mentions( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0)
- {
- $params = array();
- $params['since_id'] = $since_id;
- $params['max_id'] = $max_id;
- $params['count'] = $count;
- $params['page'] = $page;
- $params['filter_by_author'] = $filter_by_author;
- $params['filter_by_source'] = $filter_by_source;
- return $this->oauth->get( 'comments/mentions', $params );
- }
- /**
- * 根据评论ID批量返回评论信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/show_batch comments/show_batch}
- *
- * @param string $cids 需要查询的批量评论ID,用半角逗号分隔,最大50
- * @return array
- */
- function comments_show_batch( $cids )
- {
- $params = array();
- if (is_array( $cids) && !empty( $cids)) {
- foreach($cids as $k => $v) {
- $this->id_format($cids[$k]);
- }
- $params['cids'] = join(',', $cids);
- } else {
- $params['cids'] = $cids;
- }
- return $this->oauth->get( 'comments/show_batch', $params );
- }
- /**
- * 对一条微博进行评论
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/comments/create comments/create}
- *
- * @param string $comment 评论内容,内容不超过140个汉字。
- * @param int $id 需要评论的微博ID。
- * @param int $comment_ori 当评论转发微博时,是否评论给原微博,0:否、1:是,默认为0。
- * @return array
- */
- function send_comment( $id , $comment , $comment_ori = 0)
- {
- $params = array();
- $params['comment'] = $comment;
- $this->id_format($id);
- $params['id'] = $id;
- $params['comment_ori'] = $comment_ori;
- return $this->oauth->post( 'comments/create', $params );
- }
- /**
- * 删除当前用户的微博评论信息。
- *
- * 注意:只能删除自己发布的评论,发部微博的用户不可以删除其他人的评论。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/statuses/comment_destroy statuses/comment_destroy}
- *
- * @access public
- * @param int $cid 要删除的评论id
- * @return array
- */
- function comment_destroy( $cid )
- {
- $params = array();
- $params['cid'] = $cid;
- return $this->oauth->post( 'comments/destroy', $params);
- }
- /**
- * 根据评论ID批量删除评论
- *
- * 注意:只能删除自己发布的评论,发部微博的用户不可以删除其他人的评论。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/comments/destroy_batch comments/destroy_batch}
- *
- * @access public
- * @param string $ids 需要删除的评论ID,用半角逗号隔开,最多20个。
- * @return array
- */
- function comment_destroy_batch( $ids )
- {
- $params = array();
- if (is_array($ids) && !empty($ids)) {
- foreach($ids as $k => $v) {
- $this->id_format($ids[$k]);
- }
- $params['cids'] = join(',', $ids);
- } else {
- $params['cids'] = $ids;
- }
- return $this->oauth->post( 'comments/destroy_batch', $params);
- }
- /**
- * 回复一条评论
- *
- * 为防止重复,发布的信息与最后一条评论/回复信息一样话,将会被忽略。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/comments/reply comments/reply}
- *
- * @access public
- * @param int $sid 微博id
- * @param string $text 评论内容。
- * @param int $cid 评论id
- * @param int $without_mention 1:回复中不自动加入“回复@用户名”,0:回复中自动加入“回复@用户名”.默认为0.
- * @param int $comment_ori 当评论转发微博时,是否评论给原微博,0:否、1:是,默认为0。
- * @return array
- */
- function reply( $sid, $text, $cid, $without_mention = 0, $comment_ori = 0 )
- {
- $this->id_format( $sid );
- $this->id_format( $cid );
- $params = array();
- $params['id'] = $sid;
- $params['comment'] = $text;
- $params['cid'] = $cid;
- $params['without_mention'] = $without_mention;
- $params['comment_ori'] = $comment_ori;
- return $this->oauth->post( 'comments/reply', $params );
- }
- /**
- * 根据用户UID或昵称获取用户资料
- *
- * 按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/users/show users/show}
- *
- * @access public
- * @param int $uid 用户UID。
- * @return array
- */
- function show_user_by_id( $uid )
- {
- $params=array();
- if ( $uid !== NULL ) {
- $this->id_format($uid);
- $params['uid'] = $uid;
- }
- return $this->oauth->get('users/show', $params );
- }
-
- /**
- * 根据用户UID或昵称获取用户资料
- *
- * 按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/users/show users/show}
- *
- * @access public
- * @param string $screen_name 用户UID。
- * @return array
- */
- function show_user_by_name( $screen_name )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- return $this->oauth->get( 'users/show', $params );
- }
- /**
- * 通过个性化域名获取用户资料以及用户最新的一条微博
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/users/domain_show users/domain_show}
- *
- * @access public
- * @param mixed $domain 用户个性域名。例如:lazypeople,而不是http://weibo.com/lazypeople
- * @return array
- */
- function domain_show( $domain )
- {
- $params = array();
- $params['domain'] = $domain;
- return $this->oauth->get( 'users/domain_show', $params );
- }
- /**
- * 批量获取用户信息按uids
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/users/show_batch users/show_batch}
- *
- * @param string $uids 需要查询的用户ID,用半角逗号分隔,一次最多20个。
- * @return array
- */
- function users_show_batch_by_id( $uids )
- {
- $params = array();
- if (is_array( $uids ) && !empty( $uids )) {
- foreach( $uids as $k => $v ) {
- $this->id_format( $uids[$k] );
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->get( 'users/show_batch', $params );
- }
-
- /**
- * 批量获取用户信息按screen_name
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/users/show_batch users/show_batch}
- *
- * @param string $screen_name 需要查询的用户昵称,用半角逗号分隔,一次最多20个。
- * @return array
- */
- function users_show_batch_by_name( $screen_name )
- {
- $params = array();
- if (is_array( $screen_name ) && !empty( $screen_name )) {
- $params['screen_name'] = join(',', $screen_name);
- } else {
- $params['screen_name'] = $screen_name;
- }
- return $this->oauth->get( 'users/show_batch', $params );
- }
- /**
- * 获取用户的关注列表
- *
- * 如果没有提供cursor参数,将只返回最前面的5000个关注id
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/friends friendships/friends}
- *
- * @access public
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param int $uid 要获取的用户的ID。
- * @return array
- */
- function friends_by_id( $uid, $cursor = 0, $count = 50 )
- {
- $params = array();
- $params['cursor'] = $cursor;
- $params['count'] = $count;
- $params['uid'] = $uid;
- return $this->oauth->get( 'friendships/friends', $params );
- }
-
-
- /**
- * 获取用户的关注列表
- *
- * 如果没有提供cursor参数,将只返回最前面的5000个关注id
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/friends friendships/friends}
- *
- * @access public
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param string $screen_name 要获取的用户的 screen_name
- * @return array
- */
- function friends_by_name( $screen_name, $cursor = 0, $count = 50 )
- {
- $params = array();
- $params['cursor'] = $cursor;
- $params['count'] = $count;
- $params['screen_name'] = $screen_name;
- return $this->oauth->get( 'friendships/friends', $params );
- }
- /**
- * 获取两个用户之间的共同关注人列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/in_common friendships/friends/in_common}
- *
- * @param int $uid 需要获取共同关注关系的用户UID
- * @param int $suid 需要获取共同关注关系的用户UID,默认为当前登录用户。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @return array
- */
- function friends_in_common( $uid, $suid = NULL, $page = 1, $count = 50 )
- {
- $params = array();
- $params['uid'] = $uid;
- $params['suid'] = $suid;
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'friendships/friends/in_common', $params );
- }
- /**
- * 获取用户的双向关注列表,即互粉列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/bilateral friendships/friends/bilateral}
- *
- * @param int $uid 需要获取双向关注列表的用户UID。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $sort 排序类型,0:按关注时间最近排序,默认为0。
- * @return array
- **/
- function bilateral( $uid, $page = 1, $count = 50, $sort = 0 )
- {
- $params = array();
- $params['uid'] = $uid;
- $params['count'] = $count;
- $params['page'] = $page;
- $params['sort'] = $sort;
- return $this->oauth->get( 'friendships/friends/bilateral', $params );
- }
- /**
- * 获取用户的双向关注uid列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/bilateral/ids friendships/friends/bilateral/ids}
- *
- * @param int $uid 需要获取双向关注列表的用户UID。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @param int $sort 排序类型,0:按关注时间最近排序,默认为0。
- * @return array
- **/
- function bilateral_ids( $uid, $page = 1, $count = 50, $sort = 0)
- {
- $params = array();
- $params['uid'] = $uid;
- $params['count'] = $count;
- $params['page'] = $page;
- $params['sort'] = $sort;
- return $this->oauth->get( 'friendships/friends/bilateral/ids', $params );
- }
- /**
- * 获取用户的关注列表uid
- *
- * 如果没有提供cursor参数,将只返回最前面的5000个关注id
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/ids friendships/friends/ids}
- *
- * @access public
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @param int $count 每次返回的最大记录数(即页面大小),不大于5000, 默认返回500。
- * @param int $uid 要获取的用户 UID,默认为当前用户
- * @return array
- */
- function friends_ids_by_id( $uid, $cursor = 0, $count = 500 )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- $params['cursor'] = $cursor;
- $params['count'] = $count;
- return $this->oauth->get( 'friendships/friends/ids', $params );
- }
-
- /**
- * 获取用户的关注列表uid
- *
- * 如果没有提供cursor参数,将只返回最前面的5000个关注id
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/ids friendships/friends/ids}
- *
- * @access public
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @param int $count 每次返回的最大记录数(即页面大小),不大于5000, 默认返回500。
- * @param string $screen_name 要获取的用户的 screen_name,默认为当前用户
- * @return array
- */
- function friends_ids_by_name( $screen_name, $cursor = 0, $count = 500 )
- {
- $params = array();
- $params['cursor'] = $cursor;
- $params['count'] = $count;
- $params['screen_name'] = $screen_name;
- return $this->oauth->get( 'friendships/friends/ids', $params );
- }
- /**
- * 批量获取当前登录用户的关注人的备注信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/remark_batch friendships/friends/remark_batch}
- *
- * @param string $uids 需要获取备注的用户UID,用半角逗号分隔,最多不超过50个。
- * @return array
- **/
- function friends_remark_batch( $uids )
- {
- $params = array();
- if (is_array( $uids ) && !empty( $uids )) {
- foreach( $uids as $k => $v) {
- $this->id_format( $uids[$k] );
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->get( 'friendships/friends/remark_batch', $params );
- }
- /**
- * 获取用户的粉丝列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers}
- *
- * @param int $uid 需要查询的用户UID
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param int $cursor false 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @return array
- **/
- function followers_by_id( $uid , $cursor = 0 , $count = 50)
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- $params['count'] = $count;
- $params['cursor'] = $cursor;
- return $this->oauth->get( 'friendships/followers', $params );
- }
-
- /**
- * 获取用户的粉丝列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers}
- *
- * @param string $screen_name 需要查询的用户的昵称
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param int $cursor false 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @return array
- **/
- function followers_by_name( $screen_name, $cursor = 0 , $count = 50 )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- $params['count'] = $count;
- $params['cursor'] = $cursor;
- return $this->oauth->get( 'friendships/followers', $params );
- }
- /**
- * 获取用户的粉丝列表uid
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers}
- *
- * @param int $uid 需要查询的用户UID
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @return array
- **/
- function followers_ids_by_id( $uid, $cursor = 0 , $count = 50 )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- $params['count'] = $count;
- $params['cursor'] = $cursor;
- return $this->oauth->get( 'friendships/followers/ids', $params );
- }
-
- /**
- * 获取用户的粉丝列表uid
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers}
- *
- * @param string $screen_name 需要查询的用户screen_name
- * @param int $count 单页返回的记录条数,默认为50,最大不超过200。
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @return array
- **/
- function followers_ids_by_name( $screen_name, $cursor = 0 , $count = 50 )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- $params['count'] = $count;
- $params['cursor'] = $cursor;
- return $this->oauth->get( 'friendships/followers/ids', $params );
- }
- /**
- * 获取优质粉丝
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers/active friendships/followers/active}
- *
- * @param int $uid 需要查询的用户UID。
- * @param int $count 返回的记录条数,默认为20,最大不超过200。
- * @return array
- **/
- function followers_active( $uid, $count = 20)
- {
- $param = array();
- $this->id_format($uid);
- $param['uid'] = $uid;
- $param['count'] = $count;
- return $this->oauth->get( 'friendships/followers/active', $param);
- }
- /**
- * 获取当前登录用户的关注人中又关注了指定用户的用户列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends_chain/followers friendships/friends_chain/followers}
- *
- * @param int $uid 指定的关注目标用户UID。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @return array
- **/
- function friends_chain_followers( $uid, $page = 1, $count = 50 )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'friendships/friends_chain/followers', $params );
- }
- /**
- * 返回两个用户关系的详细情况
- *
- * 如果源用户或目的用户不存在,将返回http的400错误
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/show friendships/show}
- *
- * @access public
- * @param mixed $target_id 目标用户UID
- * @param mixed $source_id 源用户UID,可选,默认为当前的用户
- * @return array
- */
- function is_followed_by_id( $target_id, $source_id = NULL )
- {
- $params = array();
- $this->id_format($target_id);
- $params['target_id'] = $target_id;
- if ( $source_id != NULL ) {
- $this->id_format($source_id);
- $params['source_id'] = $source_id;
- }
- return $this->oauth->get( 'friendships/show', $params );
- }
- /**
- * 返回两个用户关系的详细情况
- *
- * 如果源用户或目的用户不存在,将返回http的400错误
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/show friendships/show}
- *
- * @access public
- * @param mixed $target_name 目标用户的微博昵称
- * @param mixed $source_name 源用户的微博昵称,可选,默认为当前的用户
- * @return array
- */
- function is_followed_by_name( $target_name, $source_name = NULL )
- {
- $params = array();
- $params['target_screen_name'] = $target_name;
- if ( $source_name != NULL ) {
- $params['source_screen_name'] = $source_name;
- }
- return $this->oauth->get( 'friendships/show', $params );
- }
- /**
- * 关注一个用户。
- *
- * 成功则返回关注人的资料,目前最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态。关注不存在的ID将返回400。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/create friendships/create}
- *
- * @access public
- * @param int $uid 要关注的用户UID
- * @return array
- */
- function follow_by_id( $uid )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- return $this->oauth->post( 'friendships/create', $params );
- }
-
- /**
- * 关注一个用户。
- *
- * 成功则返回关注人的资料,目前的最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态。关注不存在的ID将返回400。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/create friendships/create}
- *
- * @access public
- * @param string $screen_name 要关注的用户昵称
- * @return array
- */
- function follow_by_name( $screen_name )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- return $this->oauth->post( 'friendships/create', $params);
- }
- /**
- * 根据用户UID批量关注用户
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/friendships/create_batch friendships/create_batch}
- *
- * @param string $uids 要关注的用户UID,用半角逗号分隔,最多不超过20个。
- * @return array
- */
- function follow_create_batch( $uids )
- {
- $params = array();
- if (is_array($uids) && !empty($uids)) {
- foreach($uids as $k => $v) {
- $this->id_format($uids[$k]);
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->post( 'friendships/create_batch', $params);
- }
- /**
- * 取消关注某用户
- *
- * 取消关注某用户。成功则返回被取消关注人的资料,失败则返回一条字符串的说明。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/destroy friendships/destroy}
- *
- * @access public
- * @param int $uid 要取消关注的用户UID
- * @return array
- */
- function unfollow_by_id( $uid )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- return $this->oauth->post( 'friendships/destroy', $params);
- }
-
- /**
- * 取消关注某用户
- *
- * 取消关注某用户。成功则返回被取消关注人的资料,失败则返回一条字符串的说明。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/destroy friendships/destroy}
- *
- * @access public
- * @param string $screen_name 要取消关注的用户昵称
- * @return array
- */
- function unfollow_by_name( $screen_name )
- {
- $params = array();
- $params['screen_name'] = $screen_name;
- return $this->oauth->post( 'friendships/destroy', $params);
- }
- /**
- * 更新当前登录用户所关注的某个好友的备注信息
- *
- * 只能修改当前登录用户所关注的用户的备注信息。否则将给出400错误。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/friendships/remark/update friendships/remark/update}
- *
- * @access public
- * @param int $uid 需要修改备注信息的用户ID。
- * @param string $remark 备注信息。
- * @return array
- */
- function update_remark( $uid, $remark )
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- $params['remark'] = $remark;
- return $this->oauth->post( 'friendships/remark/update', $params);
- }
- /**
- * 获取当前用户最新私信列表
- *
- * 返回用户的最新n条私信,并包含发送者和接受者的详细资料。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages direct_messages}
- *
- * @access public
- * @param int $page 页码
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。
- * @param int64 $since_id 返回ID比数值since_id大(比since_id时间晚的)的私信。可选。
- * @param int64 $max_id 返回ID不大于max_id(时间不晚于max_id)的私信。可选。
- * @return array
- */
- function list_dm( $page = 1, $count = 50, $since_id = 0, $max_id = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- return $this->request_with_pager( 'direct_messages', $page, $count, $params );
- }
- /**
- * 获取当前用户发送的最新私信列表
- *
- * 返回登录用户已发送最新50条私信。包括发送者和接受者的详细资料。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages/sent direct_messages/sent}
- *
- * @access public
- * @param int $page 页码
- * @param int $count 每次返回的最大记录数,最多返回200条,默认50。
- * @param int64 $since_id 返回ID比数值since_id大(比since_id时间晚的)的私信。可选。
- * @param int64 $max_id 返回ID不大于max_id(时间不晚于max_id)的私信。可选。
- * @return array
- */
- function list_dm_sent( $page = 1, $count = 50, $since_id = 0, $max_id = 0 )
- {
- $params = array();
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- return $this->request_with_pager( 'direct_messages/sent', $page, $count, $params );
- }
- /**
- * 获取与当前登录用户有私信往来的用户列表,与该用户往来的最新私信
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/user_list direct_messages/user_list}
- *
- * @param int $count 单页返回的记录条数,默认为20。
- * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
- * @return array
- */
- function dm_user_list( $count = 20, $cursor = 0)
- {
- $params = array();
- $params['count'] = $count;
- $params['cursor'] = $cursor;
- return $this->oauth->get( 'direct_messages/user_list', $params );
- }
- /**
- * 获取与指定用户的往来私信列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/conversation direct_messages/conversation}
- *
- * @param int $uid 需要查询的用户的UID。
- * @param int $since_id 若指定此参数,则返回ID比since_id大的私信(即比since_id时间晚的私信),默认为0。
- * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的私信,默认为0。
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @return array
- */
- function dm_conversation( $uid, $page = 1, $count = 50, $since_id = 0, $max_id = 0)
- {
- $params = array();
- $this->id_format($uid);
- $params['uid'] = $uid;
- if ($since_id) {
- $this->id_format($since_id);
- $params['since_id'] = $since_id;
- }
- if ($max_id) {
- $this->id_format($max_id);
- $params['max_id'] = $max_id;
- }
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'direct_messages/conversation', $params );
- }
- /**
- * 根据私信ID批量获取私信内容
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/show_batch direct_messages/show_batch}
- *
- * @param string $dmids 需要查询的私信ID,用半角逗号分隔,一次最多50个
- * @return array
- */
- function dm_show_batch( $dmids )
- {
- $params = array();
- if (is_array($dmids) && !empty($dmids)) {
- foreach($dmids as $k => $v) {
- $this->id_format($dmids[$k]);
- }
- $params['dmids'] = join(',', $dmids);
- } else {
- $params['dmids'] = $dmids;
- }
- return $this->oauth->get( 'direct_messages/show_batch', $params );
- }
- /**
- * 发送私信
- *
- * 发送一条私信。成功将返回完整的发送消息。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages/new direct_messages/new}
- *
- * @access public
- * @param int $uid 用户UID
- * @param string $text 要发生的消息内容,文本大小必须小于300个汉字。
- * @param int $id 需要发送的微博ID。
- * @return array
- */
- function send_dm_by_id( $uid, $text, $id = NULL )
- {
- $params = array();
- $this->id_format( $uid );
- $params['text'] = $text;
- $params['uid'] = $uid;
- if ($id) {
- $this->id_format( $id );
- $params['id'] = $id;
- }
- return $this->oauth->post( 'direct_messages/new', $params );
- }
-
- /**
- * 发送私信
- *
- * 发送一条私信。成功将返回完整的发送消息。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages/new direct_messages/new}
- *
- * @access public
- * @param string $screen_name 用户昵称
- * @param string $text 要发生的消息内容,文本大小必须小于300个汉字。
- * @param int $id 需要发送的微博ID。
- * @return array
- */
- function send_dm_by_name( $screen_name, $text, $id = NULL )
- {
- $params = array();
- $params['text'] = $text;
- $params['screen_name'] = $screen_name;
- if ($id) {
- $this->id_format( $id );
- $params['id'] = $id;
- }
- return $this->oauth->post( 'direct_messages/new', $params);
- }
- /**
- * 删除一条私信
- *
- * 按ID删除私信。操作用户必须为私信的接收人。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages/destroy direct_messages/destroy}
- *
- * @access public
- * @param int $did 要删除的私信主键ID
- * @return array
- */
- function delete_dm( $did )
- {
- $this->id_format($did);
- $params = array();
- $params['id'] = $did;
- return $this->oauth->post('direct_messages/destroy', $params);
- }
- /**
- * 批量删除私信
- *
- * 批量删除当前登录用户的私信。出现异常时,返回400错误。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/direct_messages/destroy_batch direct_messages/destroy_batch}
- *
- * @access public
- * @param mixed $dids 欲删除的一组私信ID,用半角逗号隔开,或者由一组评论ID组成的数组。最多20个。例如:"4976494627, 4976262053"或array(4976494627,4976262053);
- * @return array
- */
- function delete_dms( $dids )
- {
- $params = array();
- if (is_array($dids) && !empty($dids)) {
- foreach($dids as $k => $v) {
- $this->id_format($dids[$k]);
- }
- $params['ids'] = join(',', $dids);
- } else {
- $params['ids'] = $dids;
- }
- return $this->oauth->post( 'direct_messages/destroy_batch', $params);
- }
-
- /**
- * 获取用户基本信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/basic account/profile/basic}
- *
- * @param int $uid 需要获取基本信息的用户UID,默认为当前登录用户。
- * @return array
- */
- function account_profile_basic( $uid = NULL )
- {
- $params = array();
- if ($uid) {
- $this->id_format($uid);
- $params['uid'] = $uid;
- }
- return $this->oauth->get( 'account/profile/basic', $params );
- }
- /**
- * 获取用户的教育信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/education account/profile/education}
- *
- * @param int $uid 需要获取教育信息的用户UID,默认为当前登录用户。
- * @return array
- */
- function account_education( $uid = NULL )
- {
- $params = array();
- if ($uid) {
- $this->id_format($uid);
- $params['uid'] = $uid;
- }
- return $this->oauth->get( 'account/profile/education', $params );
- }
- /**
- * 批量获取用户的教育信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/education_batch account/profile/education_batch}
- *
- * @param string $uids 需要获取教育信息的用户UID,用半角逗号分隔,最多不超过20。
- * @return array
- */
- function account_education_batch( $uids )
- {
- $params = array();
- if (is_array($uids) && !empty($uids)) {
- foreach($uids as $k => $v) {
- $this->id_format($uids[$k]);
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->get( 'account/profile/education_batch', $params );
- }
- /**
- * 获取用户的职业信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/career account/profile/career}
- *
- * @param int $uid 需要获取教育信息的用户UID,默认为当前登录用户。
- * @return array
- */
- function account_career( $uid = NULL )
- {
- $params = array();
- if ($uid) {
- $this->id_format($uid);
- $params['uid'] = $uid;
- }
- return $this->oauth->get( 'account/profile/career', $params );
- }
- /**
- * 批量获取用户的职业信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/career_batch account/profile/career_batch}
- *
- * @param string $uids 需要获取教育信息的用户UID,用半角逗号分隔,最多不超过20。
- * @return array
- */
- function account_career_batch( $uids )
- {
- $params = array();
- if (is_array($uids) && !empty($uids)) {
- foreach($uids as $k => $v) {
- $this->id_format($uids[$k]);
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->get( 'account/profile/career_batch', $params );
- }
- /**
- * 获取隐私信息设置情况
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/get_privacy account/get_privacy}
- *
- * @access public
- * @return array
- */
- function get_privacy()
- {
- return $this->oauth->get('account/get_privacy');
- }
- /**
- * 获取所有的学校列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/school_list account/profile/school_list}
- *
- * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key:
- * - province int 省份范围,省份ID。
- * - city int 城市范围,城市ID。
- * - area int 区域范围,区ID。
- * - type int 学校类型,1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为1。
- * - capital string 学校首字母,默认为A。
- * - keyword string 学校名称关键字。
- * - count int 返回的记录条数,默认为10。
- * 参数keyword与capital二者必选其一,且只能选其一。按首字母capital查询时,必须提供province参数。
- * @access public
- * @return array
- */
- function school_list( $query )
- {
- $params = $query;
- return $this->oauth->get( 'account/profile/school_list', $params );
- }
- /**
- * 获取当前登录用户的API访问频率限制情况
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/rate_limit_status account/rate_limit_status}
- *
- * @access public
- * @return array
- */
- function rate_limit_status()
- {
- return $this->oauth->get( 'account/rate_limit_status' );
- }
- /**
- * OAuth授权之后,获取授权用户的UID
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/get_uid account/get_uid}
- *
- * @access public
- * @return array
- */
- function get_uid()
- {
- return $this->oauth->get( 'account/get_uid' );
- }
- /**
- * 更改用户资料
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/basic_update account/profile/basic_update}
- *
- * @access public
- * @param array $profile 要修改的资料。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。
- * 支持修改的项:
- * - screen_name string 用户昵称,不可为空。
- * - gender i string 用户性别,m:男、f:女,不可为空。
- * - real_name string 用户真实姓名。
- * - real_name_visible int 真实姓名可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - province true int 省份代码ID,不可为空。
- * - city true int 城市代码ID,不可为空。
- * - birthday string 用户生日,格式:yyyy-mm-dd。
- * - birthday_visible int 生日可见范围,0:保密、1:只显示月日、2:只显示星座、3:所有人可见。
- * - qq string 用户QQ号码。
- * - qq_visible int 用户QQ可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - msn string 用户MSN。
- * - msn_visible int 用户MSN可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - url string 用户博客地址。
- * - url_visible int 用户博客地址可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - credentials_type int 证件类型,1:身份证、2:学生证、3:军官证、4:护照。
- * - credentials_num string 证件号码。
- * - email string 用户常用邮箱地址。
- * - email_visible int 用户常用邮箱地址可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - lang string 语言版本,zh_cn:简体中文、zh_tw:繁体中文。
- * - description string 用户描述,最长不超过70个汉字。
- * 填写birthday参数时,做如下约定:
- * - 只填年份时,采用1986-00-00格式;
- * - 只填月份时,采用0000-08-00格式;
- * - 只填某日时,采用0000-00-28格式。
- * @return array
- */
- function update_profile( $profile )
- {
- return $this->oauth->post( 'account/profile/basic_update', $profile);
- }
- /**
- * 设置教育信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/edu_update account/profile/edu_update}
- *
- * @access public
- * @param array $edu_update 要修改的学校信息。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。
- * 支持设置的项:
- * - type int 学校类型,1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为1。必填参数
- * - school_id ` int 学校代码,必填参数
- * - id string 需要修改的教育信息ID,不传则为新建,传则为更新。
- * - year int 入学年份,最小为1900,最大不超过当前年份
- * - department string 院系或者班别。
- * - visible int 开放等级,0:仅自己可见、1:关注的人可见、2:所有人可见。
- * @return array
- */
- function edu_update( $edu_update )
- {
- return $this->oauth->post( 'account/profile/edu_update', $edu_update);
- }
- /**
- * 根据学校ID删除用户的教育信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/edu_destroy account/profile/edu_destroy}
- *
- * @param int $id 教育信息里的学校ID。
- * @return array
- */
- function edu_destroy( $id )
- {
- $this->id_format( $id );
- $params = array();
- $params['id'] = $id;
- return $this->oauth->post( 'account/profile/edu_destroy', $params);
- }
- /**
- * 设置职业信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/car_update account/profile/car_update}
- *
- * @param array $car_update 要修改的职业信息。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。
- * 支持设置的项:
- * - id string 需要更新的职业信息ID。
- * - start int 进入公司年份,最小为1900,最大为当年年份。
- * - end int 离开公司年份,至今填0。
- * - department string 工作部门。
- * - visible int 可见范围,0:自己可见、1:关注人可见、2:所有人可见。
- * - province int 省份代码ID,不可为空值。
- * - city int 城市代码ID,不可为空值。
- * - company string 公司名称,不可为空值。
- * 参数province与city二者必选其一<br />
- * 参数id为空,则为新建职业信息,参数company变为必填项,参数id非空,则为更新,参数company可选
- * @return array
- */
- function car_update( $car_update )
- {
- return $this->oauth->post( 'account/profile/car_update', $car_update);
- }
- /**
- * 根据公司ID删除用户的职业信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/car_destroy account/profile/car_destroy}
- *
- * @access public
- * @param int $id 职业信息里的公司ID
- * @return array
- */
- function car_destroy( $id )
- {
- $this->id_format($id);
- $params = array();
- $params['id'] = $id;
- return $this->oauth->post( 'account/profile/car_destroy', $params);
- }
- /**
- * 更改头像
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/avatar/upload account/avatar/upload}
- *
- * @param string $image_path 要上传的头像路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法] 必须为小于700K的有效的GIF, JPG图片. 如果图片大于500像素将按比例缩放。
- * @return array
- */
- function update_profile_image( $image_path )
- {
- $params = array();
- $params['image'] = "@{$image_path}";
- return $this->oauth->post('account/avatar/upload', $params);
- }
- /**
- * 设置隐私信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/account/update_privacy account/update_privacy}
- *
- * @param array $privacy_settings 要修改的隐私设置。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。
- * 支持设置的项:
- * - comment int 是否可以评论我的微博,0:所有人、1:关注的人,默认为0。
- * - geo int 是否开启地理信息,0:不开启、1:开启,默认为1。
- * - message int 是否可以给我发私信,0:所有人、1:关注的人,默认为0。
- * - realname int 是否可以通过真名搜索到我,0:不可以、1:可以,默认为0。
- * - badge int 勋章是否可见,0:不可见、1:可见,默认为1。
- * - mobile int 是否可以通过手机号码搜索到我,0:不可以、1:可以,默认为0。
- * 以上参数全部选填
- * @return array
- */
- function update_privacy( $privacy_settings )
- {
- return $this->oauth->post( 'account/update_privacy', $privacy_settings);
- }
- /**
- * 获取当前用户的收藏列表
- *
- * 返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/favorites favorites}
- *
- * @access public
- * @param int $page 返回结果的页码,默认为1。
- * @param int $count 单页返回的记录条数,默认为50。
- * @return array
- */
- function get_favorites( $page = 1, $count = 50 )
- {
- $params = array();
- $params['page'] = intval($page);
- $params['count'] = intval($count);
- return $this->oauth->get( 'favorites', $params );
- }
- /**
- * 根据收藏ID获取指定的收藏信息
- *
- * 根据收藏ID获取指定的收藏信息。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/favorites/show favorites/show}
- *
- * @access public
- * @param int $id 需要查询的收藏ID。
- * @return array
- */
- function favorites_show( $id )
- {
- $params = array();
- $this->id_format($id);
- $params['id'] = $id;
- return $this->oauth->get( 'favorites/show', $params );
- }
- /**
- * 根据标签获取当前登录用户该标签下的收藏列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/by_tags favorites/by_tags}
- *
- *
- * @param int $tid 需要查询的标签ID。'
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @return array
- */
- function favorites_by_tags( $tid, $page = 1, $count = 50)
- {
- $params = array();
- $params['tid'] = $tid;
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'favorites/by_tags', $params );
- }
- /**
- * 获取当前登录用户的收藏标签列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags favorites/tags}
- *
- * @access public
- * @param int $count 单页返回的记录条数,默认为50。
- * @param int $page 返回结果的页码,默认为1。
- * @return array
- */
- function favorites_tags( $page = 1, $count = 50)
- {
- $params = array();
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'favorites/tags', $params );
- }
- /**
- * 收藏一条微博信息
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/create favorites/create}
- *
- * @access public
- * @param int $sid 收藏的微博id
- * @return array
- */
- function add_to_favorites( $sid )
- {
- $this->id_format($sid);
- $params = array();
- $params['id'] = $sid;
- return $this->oauth->post( 'favorites/create', $params );
- }
- /**
- * 删除微博收藏。
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/destroy favorites/destroy}
- *
- * @access public
- * @param int $id 要删除的收藏微博信息ID.
- * @return array
- */
- function remove_from_favorites( $id )
- {
- $this->id_format($id);
- $params = array();
- $params['id'] = $id;
- return $this->oauth->post( 'favorites/destroy', $params);
- }
- /**
- * 批量删除微博收藏。
- *
- * 批量删除当前登录用户的收藏。出现异常时,返回HTTP400错误。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/favorites/destroy_batch favorites/destroy_batch}
- *
- * @access public
- * @param mixed $fids 欲删除的一组私信ID,用半角逗号隔开,或者由一组评论ID组成的数组。最多20个。例如:"231101027525486630,201100826122315375"或array(231101027525486630,201100826122315375);
- * @return array
- */
- function remove_from_favorites_batch( $fids )
- {
- $params = array();
- if (is_array($fids) && !empty($fids)) {
- foreach ($fids as $k => $v) {
- $this->id_format($fids[$k]);
- }
- $params['ids'] = join(',', $fids);
- } else {
- $params['ids'] = $fids;
- }
- return $this->oauth->post( 'favorites/destroy_batch', $params);
- }
- /**
- * 更新一条收藏的收藏标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/update favorites/tags/update}
- *
- * @access public
- * @param int $id 需要更新的收藏ID。
- * @param string $tags 需要更新的标签内容,用半角逗号分隔,最多不超过2条。
- * @return array
- */
- function favorites_tags_update( $id, $tags )
- {
- $params = array();
- $params['id'] = $id;
- if (is_array($tags) && !empty($tags)) {
- foreach ($tags as $k => $v) {
- $this->id_format($tags[$k]);
- }
- $params['tags'] = join(',', $tags);
- } else {
- $params['tags'] = $tags;
- }
- return $this->oauth->post( 'favorites/tags/update', $params );
- }
- /**
- * 更新当前登录用户所有收藏下的指定标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/update_batch favorites/tags/update_batch}
- *
- * @param int $tid 需要更新的标签ID。必填
- * @param string $tag 需要更新的标签内容。必填
- * @return array
- */
- function favorites_update_batch( $tid, $tag )
- {
- $params = array();
- $params['tid'] = $tid;
- $params['tag'] = $tag;
- return $this->oauth->post( 'favorites/tags/update_batch', $params);
- }
- /**
- * 删除当前登录用户所有收藏下的指定标签
- *
- * 删除标签后,该用户所有收藏中,添加了该标签的收藏均解除与该标签的关联关系
- * <br />对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/destroy_batch favorites/tags/destroy_batch}
- *
- * @param int $tid 需要更新的标签ID。必填
- * @return array
- */
- function favorites_tags_destroy_batch( $tid )
- {
- $params = array();
- $params['tid'] = $tid;
- return $this->oauth->post( 'favorites/tags/destroy_batch', $params);
- }
- /**
- * 获取某用户的话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends trends}
- *
- * @param int $uid 查询用户的ID。默认为当前用户。可选。
- * @param int $page 指定返回结果的页码。可选。
- * @param int $count 单页大小。缺省值10。可选。
- * @return array
- */
- function get_trends( $uid = NULL, $page = 1, $count = 10 )
- {
- $params = array();
- if ($uid) {
- $params['uid'] = $uid;
- } else {
- $user_info = $this->get_uid();
- $params['uid'] = $user_info['uid'];
- }
- $this->id_format( $params['uid'] );
- $params['page'] = $page;
- $params['count'] = $count;
- return $this->oauth->get( 'trends', $params );
- }
- /**
- * 判断当前用户是否关注某话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/is_follow trends/is_follow}
- *
- * @access public
- * @param string $trend_name 话题关键字。
- * @return array
- */
- function trends_is_follow( $trend_name )
- {
- $params = array();
- $params['trend_name'] = $trend_name;
- return $this->oauth->get( 'trends/is_follow', $params );
- }
- /**
- * 返回最近一小时内的热门话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/hourly trends/hourly}
- *
- * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。
- * @return array
- */
- function hourly_trends( $base_app = 0 )
- {
- $params = array();
- $params['base_app'] = $base_app;
- return $this->oauth->get( 'trends/hourly', $params );
- }
- /**
- * 返回最近一天内的热门话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/daily trends/daily}
- *
- * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。
- * @return array
- */
- function daily_trends( $base_app = 0 )
- {
- $params = array();
- $params['base_app'] = $base_app;
- return $this->oauth->get( 'trends/daily', $params );
- }
- /**
- * 返回最近一周内的热门话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/weekly trends/weekly}
- *
- * @access public
- * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。
- * @return array
- */
- function weekly_trends( $base_app = 0 )
- {
- $params = array();
- $params['base_app'] = $base_app;
- return $this->oauth->get( 'trends/weekly', $params );
- }
- /**
- * 关注某话题
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/follow trends/follow}
- *
- * @access public
- * @param string $trend_name 要关注的话题关键词。
- * @return array
- */
- function follow_trends( $trend_name )
- {
- $params = array();
- $params['trend_name'] = $trend_name;
- return $this->oauth->post( 'trends/follow', $params );
- }
- /**
- * 取消对某话题的关注
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/trends/destroy trends/destroy}
- *
- * @access public
- * @param int $tid 要取消关注的话题ID。
- * @return array
- */
- function unfollow_trends( $tid )
- {
- $this->id_format($tid);
- $params = array();
- $params['trend_id'] = $tid;
- return $this->oauth->post( 'trends/destroy', $params );
- }
- /**
- * 返回指定用户的标签列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags tags}
- *
- * @param int $uid 查询用户的ID。默认为当前用户。可选。
- * @param int $page 指定返回结果的页码。可选。
- * @param int $count 单页大小。缺省值20,最大值200。可选。
- * @return array
- */
- function get_tags( $uid = NULL, $page = 1, $count = 20 )
- {
- $params = array();
- if ( $uid ) {
- $params['uid'] = $uid;
- } else {
- $user_info = $this->get_uid();
- $params['uid'] = $user_info['uid'];
- }
- $this->id_format( $params['uid'] );
- $params['page'] = $page;
- $params['count'] = $count;
- return $this->oauth->get( 'tags', $params );
- }
- /**
- * 批量获取用户的标签列表
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags/tags_batch tags/tags_batch}
- *
- * @param string $uids 要获取标签的用户ID。最大20,逗号分隔。必填
- * @return array
- */
- function get_tags_batch( $uids )
- {
- $params = array();
- if (is_array( $uids ) && !empty( $uids )) {
- foreach ($uids as $k => $v) {
- $this->id_format( $uids[$k] );
- }
- $params['uids'] = join(',', $uids);
- } else {
- $params['uids'] = $uids;
- }
- return $this->oauth->get( 'tags/tags_batch', $params );
- }
- /**
- * 返回用户感兴趣的标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags/suggestions tags/suggestions}
- *
- * @access public
- * @param int $count 单页大小。缺省值10,最大值10。可选。
- * @return array
- */
- function get_suggest_tags( $count = 10)
- {
- $params = array();
- $params['count'] = intval($count);
- return $this->oauth->get( 'tags/suggestions', $params );
- }
- /**
- * 为当前登录用户添加新的用户标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags/create tags/create}
- *
- * @access public
- * @param mixed $tags 要创建的一组标签,每个标签的长度不可超过7个汉字,14个半角字符。多个标签之间用逗号间隔,或由多个标签构成的数组。如:"abc,drf,efgh,tt"或array("abc", "drf", "efgh", "tt")
- * @return array
- */
- function add_tags( $tags )
- {
- $params = array();
- if (is_array($tags) && !empty($tags)) {
- $params['tags'] = join(',', $tags);
- } else {
- $params['tags'] = $tags;
- }
- return $this->oauth->post( 'tags/create', $params);
- }
- /**
- * 删除标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags/destroy tags/destroy}
- *
- * @access public
- * @param int $tag_id 标签ID,必填参数
- * @return array
- */
- function delete_tag( $tag_id )
- {
- $params = array();
- $params['tag_id'] = $tag_id;
- return $this->oauth->post( 'tags/destroy', $params );
- }
- /**
- * 批量删除标签
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/tags/destroy_batch tags/destroy_batch}
- *
- * @access public
- * @param mixed $ids 必选参数,要删除的tag id,多个id用半角逗号分割,最多10个。或由多个tag id构成的数组。如:“553,554,555"或array(553, 554, 555)
- * @return array
- */
- function delete_tags( $ids )
- {
- $params = array();
- if (is_array($ids) && !empty($ids)) {
- $params['ids'] = join(',', $ids);
- } else {
- $params['ids'] = $ids;
- }
- return $this->oauth->post( 'tags/destroy_batch', $params );
- }
- /**
- * 验证昵称是否可用,并给予建议昵称
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/register/verify_nickname register/verify_nickname}
- *
- * @param string $nickname 需要验证的昵称。4-20个字符,支持中英文、数字、"_"或减号。必填
- * @return array
- */
- function verify_nickname( $nickname )
- {
- $params = array();
- $params['nickname'] = $nickname;
- return $this->oauth->get( 'register/verify_nickname', $params );
- }
- /**
- * 搜索用户时的联想搜索建议
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/users search/suggestions/users}
- *
- * @param string $q 搜索的关键字,必须做URLencoding。必填,中间最好不要出现空格
- * @param int $count 返回的记录条数,默认为10。
- * @return array
- */
- function search_users( $q, $count = 10 )
- {
- $params = array();
- $params['q'] = $q;
- $params['count'] = $count;
- return $this->oauth->get( 'search/suggestions/users', $params );
- }
- /**
- * 搜索微博时的联想搜索建议
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/statuses search/suggestions/statuses}
- *
- * @param string $q 搜索的关键字,必须做URLencoding。必填
- * @param int $count 返回的记录条数,默认为10。
- * @return array
- */
- function search_statuses( $q, $count = 10)
- {
- $params = array();
- $params['q'] = $q;
- $params['count'] = $count;
- return $this->oauth->get( 'search/suggestions/statuses', $params );
- }
- /**
- * 搜索学校时的联想搜索建议
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/schools search/suggestions/schools}
- *
- * @param string $q 搜索的关键字,必须做URLencoding。必填
- * @param int $count 返回的记录条数,默认为10。
- * @param int type 学校类型,0:全部、1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为0。选填
- * @return array
- */
- function search_schools( $q, $count = 10, $type = 1)
- {
- $params = array();
- $params['q'] = $q;
- $params['count'] = $count;
- $params['type'] = $type;
- return $this->oauth->get( 'search/suggestions/schools', $params );
- }
- /**
- * 搜索公司时的联想搜索建议
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/companies search/suggestions/companies}
- *
- * @param string $q 搜索的关键字,必须做URLencoding。必填
- * @param int $count 返回的记录条数,默认为10。
- * @return array
- */
- function search_companies( $q, $count = 10)
- {
- $params = array();
- $params['q'] = $q;
- $params['count'] = $count;
- return $this->oauth->get( 'search/suggestions/companies', $params );
- }
- /**
- * @用户时的联想建议
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/at_users search/suggestions/at_users}
- *
- * @param string $q 搜索的关键字,必须做URLencoding。必填
- * @param int $count 返回的记录条数,默认为10。
- * @param int $type 联想类型,0:关注、1:粉丝。必填
- * @param int $range 联想范围,0:只联想关注人、1:只联想关注人的备注、2:全部,默认为2。选填
- * @return array
- */
- function search_at_users( $q, $count = 10, $type=0, $range = 2)
- {
- $params = array();
- $params['q'] = $q;
- $params['count'] = $count;
- $params['type'] = $type;
- $params['range'] = $range;
- return $this->oauth->get( 'search/suggestions/at_users', $params );
- }
-
- /**
- * 搜索与指定的一个或多个条件相匹配的微博
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/statuses search/statuses}
- *
- * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key:
- * - q string 搜索的关键字,必须进行URLencode。
- * - filter_ori int 过滤器,是否为原创,0:全部、1:原创、2:转发,默认为0。
- * - filter_pic int 过滤器。是否包含图片,0:全部、1:包含、2:不包含,默认为0。
- * - fuid int 搜索的微博作者的用户UID。
- * - province int 搜索的省份范围,省份ID。
- * - city int 搜索的城市范围,城市ID。
- * - starttime int 开始时间,Unix时间戳。
- * - endtime int 结束时间,Unix时间戳。
- * - count int 单页返回的记录条数,默认为10。
- * - page int 返回结果的页码,默认为1。
- * - needcount boolean 返回结果中是否包含返回记录数,true:返回、false:不返回,默认为false。
- * - base_app int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * needcount参数不同,会导致相应的返回值结构不同
- * 以上参数全部选填
- * @return array
- */
- function search_statuses_high( $query )
- {
- return $this->oauth->get( 'search/statuses', $query );
- }
- /**
- * 通过关键词搜索用户
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/search/users search/users}
- *
- * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key:
- * - q string 搜索的关键字,必须进行URLencode。
- * - snick int 搜索范围是否包含昵称,0:不包含、1:包含。
- * - sdomain int 搜索范围是否包含个性域名,0:不包含、1:包含。
- * - sintro int 搜索范围是否包含简介,0:不包含、1:包含。
- * - stag int 搜索范围是否包含标签,0:不包含、1:包含。
- * - province int 搜索的省份范围,省份ID。
- * - city int 搜索的城市范围,城市ID。
- * - gender string 搜索的性别范围,m:男、f:女。
- * - comorsch string 搜索的公司学校名称。
- * - sort int 排序方式,1:按更新时间、2:按粉丝数,默认为1。
- * - count int 单页返回的记录条数,默认为10。
- * - page int 返回结果的页码,默认为1。
- * - base_app int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
- * 以上所有参数全部选填
- * @return array
- */
- function search_users_keywords( $query )
- {
- return $this->oauth->get( 'search/users', $query );
- }
- /**
- * 获取系统推荐用户
- *
- * 返回系统推荐的用户列表。
- * <br />对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/hot suggestions/users/hot}
- *
- * @access public
- * @param string $category 分类,可选参数,返回某一类别的推荐用户,默认为 default。如果不在以下分类中,返回空列表:<br />
- * - default:人气关注
- * - ent:影视名星
- * - hk_famous:港台名人
- * - model:模特
- * - cooking:美食&健康
- * - sport:体育名人
- * - finance:商界名人
- * - tech:IT互联网
- * - singer:歌手
- * - writer:作家
- * - moderator:主持人
- * - medium:媒体总编
- * - stockplayer:炒股高手
- * @return array
- */
- function hot_users( $category = "default" )
- {
- $params = array();
- $params['category'] = $category;
- return $this->oauth->get( 'suggestions/users/hot', $params );
- }
- /**
- * 获取用户可能感兴趣的人
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/may_interested suggestions/users/may_interested}
- *
- * @access public
- * @param int $page 返回结果的页码,默认为1。
- * @param int $count 单页返回的记录条数,默认为10。
- * @return array
- * @ignore
- */
- function suggestions_may_interested( $page = 1, $count = 10 )
- {
- $params = array();
- $params['page'] = $page;
- $params['count'] = $count;
- return $this->oauth->get( 'suggestions/users/may_interested', $params);
- }
- /**
- * 根据一段微博正文推荐相关微博用户。
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/by_status suggestions/users/by_status}
- *
- * @access public
- * @param string $content 微博正文内容。
- * @param int $num 返回结果数目,默认为10。
- * @return array
- */
- function suggestions_users_by_status( $content, $num = 10 )
- {
- $params = array();
- $params['content'] = $content;
- $params['num'] = $num;
- return $this->oauth->get( 'suggestions/users/by_status', $params);
- }
- /**
- * 热门收藏
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/favorites/hot suggestions/favorites/hot}
- *
- * @param int $count 每页返回结果数,默认20。选填
- * @param int $page 返回页码,默认1。选填
- * @return array
- */
- function hot_favorites( $page = 1, $count = 20 )
- {
- $params = array();
- $params['count'] = $count;
- $params['page'] = $page;
- return $this->oauth->get( 'suggestions/favorites/hot', $params);
- }
- /**
- * 把某人标识为不感兴趣的人
- *
- * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/not_interested suggestions/users/not_interested}
- *
- * @param int $uid 不感兴趣的用户的UID。
- * @return array
- */
- function put_users_not_interested( $uid )
- {
- $params = array();
- $params['uid'] = $uid;
- return $this->oauth->post( 'suggestions/users/not_interested', $params);
- }
- // =========================================
- /**
- * @ignore
- */
- protected function request_with_pager( $url, $page = false, $count = false, $params = array() )
- {
- if( $page ) $params['page'] = $page;
- if( $count ) $params['count'] = $count;
- return $this->oauth->get($url, $params );
- }
- /**
- * @ignore
- */
- protected function request_with_uid( $url, $uid_or_name, $page = false, $count = false, $cursor = false, $post = false, $params = array())
- {
- if( $page ) $params['page'] = $page;
- if( $count ) $params['count'] = $count;
- if( $cursor )$params['cursor'] = $cursor;
- if( $post ) $method = 'post';
- else $method = 'get';
- if ( $uid_or_name !== NULL ) {
- $this->id_format($uid_or_name);
- $params['id'] = $uid_or_name;
- }
- return $this->oauth->$method($url, $params );
- }
- /**
- * @ignore
- */
- protected function id_format(&$id) {
- if ( is_float($id) ) {
- $id = number_format($id, 0, '', '');
- } elseif ( is_string($id) ) {
- $id = trim($id);
- }
- }
- }
|