2 if (get_magic_quotes_gpc()) {
4 $_REQUEST = array_map('stripslashes', $_REQUEST);
5 $_GET = array_map('stripslashes', $_GET);
6 $_POST = array_map('stripslashes', $_POST);
7 $_COOKIE = array_map('stripslashes', $_COOKIE);
13 var $user_agent='API';
16 var $headers=array('Expect:', 'X-Twitter-Client: ','X-Twitter-Client-Version: ','X-Twitter-Client-URL: ');
17 var $responseInfo=array();
18 var $suppress_response_code = false;
21 public $connecttimeout = 5;
23 function twitter($username = '', $password = '', $type = 'json')
25 if ($username != '' && $password != '') {
26 $this->username = $username;
27 $this->password = $password;
34 $request = API_URL . '/account/verify_credentials.' . $this->type;
35 return $this->objectify( $this->process($request, false, 0) );
38 /**** Get user theme ****/
41 $twit = $this->veverify();
42 $theme = array( 'background-color' => $twit->profile_background_color, 'background-image-url' => $twit->profile_background_image_url, 'background-tile' => $twit->profile_background_tile == true ? 'repeat' : 'no-repeat', 'link-color' => $twit->profile_link_color, 'sidebar-border-color' => $twit->profile_sidebar_border_color, 'sidebar-fill-color' => $twit->profile_sidebar_fill_color, 'text-color' => $twit->profile_text_color);
47 /**** Status Methods ****/
49 function showStatus( $id )
51 if( !in_array( $this->type, array( 'xml','json' ) ) )
54 $request = API_URL . '/statuses/show/'.$id . '.' . $this->type;
55 return $this->objectify( $this->process($request) );
58 function update( $status, $replying_to = false )
60 if( !in_array( $this->type, array( 'xml','json' ) ) )
65 $args['status'] = $status;
67 $args['in_reply_to_status_id'] = $replying_to;
68 $args['source'] = 'API';
72 $qs = $this->_glue( $args );
74 $request = API_URL . '/statuses/update.' . $this->type . $qs;
76 return $this->objectify( $this->process($request, true) );
79 function deleteStatus( $id ) {
80 if( !in_array( $this->type, array( 'xml','json' ) ) )
83 $request = API_URL . '/statuses/destroy/' . $id . '.' . $this->type;
84 return $this->objectify( $this->process( $request, true ) );
88 /**** Timeline Methods ****/
90 function publicTimeline( $sinceid = false )
92 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
96 if( $sinceid !== false )
97 $qs = '?since_id=' . intval($sinceid);
98 $request = API_URL . '/statuses/public_timeline.' . $this->type . $qs;
100 return $this->objectify( $this->process($request) );
103 function userTimeline($page=false,$id=false,$count=false,$since_id=false)
105 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
112 $args['count'] = (int) $count;
114 $args['since_id'] = (int) $since_id;
116 $args['page'] = (int) $page;
119 if( !empty( $args ) )
120 $qs = $this->_glue( $args );
123 $request = API_URL . '/statuses/user_timeline.' . $this->type . $qs;
125 $request = API_URL . '/statuses/user_timeline/' . rawurlencode($id) . '.' . $this->type . $qs;
126 $response = $this->process($request);
127 if($response == false){
130 return $this->objectify($response);
134 function friendsTimeline( $page = false, $since_id = false, $count = false )
136 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
141 $args['count'] = $count;
143 $args['since_id'] = $since_id;
145 $args['page'] = (int) $page;
148 if( !empty( $args ) )
149 $qs = $this->_glue( $args );
151 $request = API_URL . '/statuses/friends_timeline.' . $this->type . $qs;
152 return $this->objectify( $this->process($request) );
156 function replies( $page = false, $since_id = false )
158 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
163 $args['page'] = (int) $page;
165 $args['since_id'] = $since_id;
168 if( !empty( $args ) )
169 $qs = $this->_glue( $args );
171 $request = API_URL . '/statuses/mentions.' . $this->type . $qs;
173 return $this->objectify( $this->process($request) );
178 /**** Direct Message Methods ****/
180 function directMessages( $page = false, $since_id = false, $count = null )
182 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
188 $qsparams['since_id'] = $since_id;
190 $qsparams['page'] = (int) $page;
192 $request = API_URL . '/direct_messages.' . $this->type . '?' . $this->arrToStr($qsparams);
194 return $this->objectify( $this->process($request) );
197 function sentDirectMessage( $page = false, $since = false, $since_id = false )
199 if( !in_array( $this->type, array( 'xml','json' ) ) )
204 if( $since !== false )
205 $qsparams['since'] = rawurlencode($since);
207 $qsparams['since_id'] = (int) $since_id;
209 $qsparams['page'] = (int) $page;
211 $request = API_URL . '/direct_messages/sent.' . $this->type . '?' . $this->arrToStr($qsparams);
212 return $this->objectify( $this->process($request) );
215 function sendDirectMessage( $user, $text )
217 if( !in_array( $this->type, array( 'xml','json' ) ) )
220 $request = API_URL . '/direct_messages/new.' . $this->type;
221 $postargs = 'user=' . rawurlencode($user) . '&text=' . rawurlencode($text);
223 return $this->objectify( $this->process($request, $postargs) );
226 function deleteDirectMessage( $id )
228 if( !in_array( $this->type, array( 'xml','json' ) ) )
231 $request = API_URL . '/direct_messages/destroy/' . $id . '.' . $this->type;
232 return $this->objectify( $this->process( $request, true ) );
236 /**** User Methods ****/
238 function showUser( $id = false , $email = false, $user_id = false, $screen_name=false )
240 if( !in_array( $this->type, array( 'xml','json' ) ) )
244 $id = $this->username;
246 $qs = '?user_id=' . $user_id;
247 elseif ( $screen_name ) :
248 $qs = '?screen_name=' . (string) $screen_name;
250 $qs = '?email=' . (string) $email;
256 $request = API_URL . '/users/show/' . $qs . '.' . $this->type;
258 return $this->objectify( $this->process($request) );
261 function friends( $id = false, $page = false , $count = 30 )
263 if( !in_array( $this->type, array( 'xml','json' ) ) )
270 $args['count'] = (int) $count;
271 $args['cursor'] = $page ? $page : -1; // ¸ü»»ÁËÅжϱí´ïʽ
273 if( !empty( $args ) )
274 $qs = $this->_glue( $args );
276 $request = API_URL . ($id ? "/statuses/friends/$id.$this->type" : "/statuses/friends.$this->type");
278 return $this->objectify( $this->process($request) );
281 function relationship($target, $source = false){
282 if($target == $this->username){
286 $args['target_screen_name'] = $target;
288 $args['source_screen_name'] = $source;
290 $request = API_TWITTER."/1/friendships/show.$this->type".$this->_glue($args);
291 return $this->objectify($this->process($request));
294 function followers( $id = false, $page = false , $count = 30 )
296 if( !in_array( $this->type, array( 'xml','json' ) ) )
303 $args['count'] = (int) $count;
304 $args['cursor'] = $page ? $page : -1; // ¸ü»»ÁËÅжϱí´ïʽ
306 if( !empty( $args ) )
307 $qs = $this->_glue( $args );
309 $request = API_URL . ($id ? "/statuses/followers/$id.$this->type" : "/statuses/followers.$this->type");
312 return $this->objectify( $this->process($request) );
315 /****** Favorites ******/
317 function getFavorites( $page=false )
319 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
323 $qs = '?page=' . $page;
325 $request = API_URL . '/favorites.' . $this->type . $qs;
326 return $this->objectify( $this->process($request) );
329 function makeFavorite( $id )
331 if( !in_array( $this->type, array( 'xml','json' ) ) )
334 $request = API_URL . '/favorites/create/' . $id . '.' . $this->type;
335 return $this->objectify( $this->process($request, $args) );
338 function removeFavorite( $id )
340 if( !in_array( $this->type, array( 'xml','json' ) ) )
343 $request = API_URL . '/favorites/destroy/' . $id . '.' . $this->type;
344 return $this->objectify( $this->process($request, true) );
348 /**** Friendship Methods ****/
350 function isFriend( $user_a, $user_b )
352 if( !in_array( $this->type, array( 'xml','json' ) ) )
356 $args['user_a'] = $user_a;
357 $args['user_b'] = $user_b;
358 $qs = $this->_glue( $args );
360 $request = API_URL . '/friendships/exists.' . $this->type . $qs;
361 return $this->objectify( $this->process($request) );
364 function followUser( $id, $notifications = false )
366 if( !in_array( $this->type, array( 'xml','json' ) ) )
369 $request = API_URL . '/friendships/create/' . $id . '.' . $this->type;
371 $request .= '?follow=true';
373 return $this->objectify( $this->process($request, true) );
376 function destroyUser( $id )
378 if( !in_array( $this->type, array( 'xml','json' ) ) )
381 $request = API_URL . '/friendships/destroy/' . $id . '.' . $this->type;
382 return $this->objectify( $this->process($request, true) );
385 /****** Block Methods ******/
386 function blockingList($page = false){
387 $url = API_URL."/blocks/blocking.$this->type";
389 $url .= "?page=$page";
391 return $this->objectify($this->process($url));
394 function blockingIDs(){
395 $url = API_URL."blocks/blocking/ids.$this->type";
396 return $this->objectify($this->process($url));
399 function blockUser($id)
401 if( !in_array( $this->type, array( 'xml','json' ) ) )
403 $request = API_URL . '/blocks/create/' . $id . '.' . $this->type;
405 $arps['post_method'] = 1;
406 $result = $this->curl_process($request, $args);
407 if($result->error == 'Not found'){
414 function unblockUser($id)
416 if( !in_array( $this->type, array( 'xml','json' ) ) )
418 $request = API_URL . '/blocks/destroy/' . $id . '.' . $this->type;
420 $arps['post_method'] = 1;
421 $result = $this->curl_process($request, $args);
422 if($result->error == 'Not found'){
429 function isBlocked($id)
431 $request = API_URL . '/blocks/exists/' . $id . '.' . $this->type;
432 $result = $this->curl_process($request);
433 if($result->error == 'Not found'){
440 /****** Trends ******/
442 $url = "http://search.twitter.com/trends.$this->type";
443 return $this->curl_process($url);
446 /* ---------- Spam ---------- */
447 function reportSpam($screen_name){
448 $url = API_TWITTER."/1/report_spam.$this->type";
450 $args['screen_name'] = $screen_name;
451 return $this->curl_process($url, $args);
454 /****** Social Graph ******/
456 function socialGraphFollowing( $id = false)
458 if( !in_array( $this->type, array( 'xml','json' ) ) )
461 $request = API_URL . '/friends/ids';
463 $request .= '/' . (int) $id . '.' . $this->type;
465 return $this->objectify( $this->process($request) );
468 function socialGraphFollowedBy( $id = false )
470 if( !in_array( $this->type, array( 'xml','json' ) ) )
473 $request = API_URL . '/followers/ids';
475 $request .= '/' . (int) $id . '.' . $this->type;
477 return $this->objectify( $this->process($request) );
481 /****** Account Methods ******/
483 function updateDevice( $device )
485 if( !in_array( $this->type, array( 'xml','json' ) ) )
488 if( !in_array( $device, array('im','sms','none') ) )
491 $qs = '?device=' . $device;
492 $request = API_URL . '/account/update_delivery_device.' . $this->type . $qs;
493 return $this->objectify( $this->process( $request ) );
496 function updateAvatar( $file )
498 if( !in_array( $this->type, array( 'xml','json' ) ) )
501 // Adding @ ensures the POST will be raw multipart data encoded. This MUST be a file, not a URL. Handle it outside of the class.
502 $postdata = array( 'image' => "@$file");
503 $request = API_URL . '/account/update_profile_image.' . $this->type;
504 return $this->objectify( $this->process( $request, $postdata ) );
507 function updateBackground( $file )
509 if( !in_array( $this->type, array( 'xml','json' ) ) )
512 // Adding @ ensures the POST will be raw multipart data encoded. This MUST be a file, not a URL. Handle it outside of the class.
513 $postdata = array( 'image' => "@$file");
514 $request = API_URL . '/account/update_profile_background_image.' . $this->type;
515 return $this->objectify( $this->process( $request, $postdata ) );
518 function updateProfile( $fields = array() )
520 if( !in_array( $this->type, array( 'xml','json' ) ) )
524 foreach( $fields as $pk => $pv ) :
528 $postdata[$pk] = (string) substr( $pv, 0, 20 );
531 if( preg_match( '/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $pv ) )
532 $postdata[$pk] = (string) $pv;
535 $postdata[$pk] = (string) substr( $pv, 0, 100 );
538 $postdata[$pk] = (string) substr( $pv, 0, 30 );
541 $postdata[$pk] = (string) substr( $pv, 0, 160 );
548 $request = API_URL . '/account/update_profile.' . $this->type;
549 return $this->objectify( $this->process( $request, $postdata ) );
552 function updateColors( $colors = array() )
554 if( !in_array( $this->type, array( 'xml','json' ) ) )
558 foreach( $colors as $ck => $cv ) :
559 if( preg_match('/^(?:(?:[a-f\d]{3}){1,2})$/i', $hex) ) :
560 $postdata[$ck] = (string) $cv;
564 $request = API_URL . '/account/update_profile_colors.' . $this->type;
565 return $this->objectify( $this->process( $request, $postdata ) );
569 /**** Search Method ****/
571 function search( $q = false, $page = false, $rpp = false)
575 $qs = '?q='.urlencode($q);
577 $qs .= '&page='.$page;
581 $searchApiUrl = strpos(API_URL, "twitter.com") > 0 ? "http://search.twitter.com" : API_URL;
582 $request = $searchApiUrl . '/search.' . $this->type . $qs;
584 return $this->objectify( $this->process($request) );
587 /**** List Method ****/
589 function createdLists( $username = '', $cursor = false )
591 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
596 $args['cursor'] = $cursor;
599 if( !empty( $args ) )
600 $qs = $this->_glue( $args );
602 $request = API_URL . '/' . $username . '/lists.' . $this->type . $qs;
604 return $this->objectify( $this->process($request) );
608 function followedLists( $username = '', $cursor = false )
610 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
615 $args['cursor'] = $cursor;
618 if( !empty( $args ) )
619 $qs = $this->_glue( $args );
621 $request = API_URL . '/' . $username . '/lists/subscriptions.' . $this->type . $qs;
623 return $this->objectify( $this->process($request) );
627 function beAddedLists( $username = '', $cursor = false )
629 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
634 $args['cursor'] = $cursor;
637 if( !empty( $args ) )
638 $qs = $this->_glue( $args );
640 $request = API_URL . '/' . $username . '/lists/memberships.' . $this->type . $qs;
642 return $this->objectify( $this->process($request) );
646 //id¸ñʽ£ºusername/listname Àý:bang590/temp ÏÂͬ
647 function listStatus( $id, $page = false, $since_id = false )
649 if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
656 $arr = explode('/', $id);
657 if (count($arr) != 2) return false;
663 $args['page'] = (int) $page;
665 $args['since_id'] = $since_id;
668 if( !empty( $args ) )
669 $qs = $this->_glue( $args );
671 $request = API_URL . "/$username/lists/$listname/statuses." . $this->type . $qs;
673 return $this->objectify( $this->process($request) );
677 function listInfo( $id ) {
678 if( !in_array( $this->type, array( 'xml','json' ) ) )
685 $arr = explode('/', $id);
686 if (count($arr) != 2) return false;
690 $request = API_URL . "/$username/lists/$listname." . $this->type;
691 return $this->objectify( $this->process($request) );
694 function isFollowedList( $id )
696 if( !in_array( $this->type, array( 'xml','json' ) ) )
699 $arr = explode('/', $id);
700 if (count($arr) != 2) return false;
704 $request = API_URL . "/$username/$listname/subscribers/$this->username." . $this->type;
705 return $this->objectify( $this->process($request) );
709 function listMembers( $id, $cursor = false )
711 if( !in_array( $this->type, array( 'xml','json' ) ) )
714 $arr = explode('/', $id);
715 if (count($arr) != 2) return false;
721 $args['cursor'] = $cursor;
723 if( !empty( $args ) )
724 $qs = $this->_glue( $args );
726 $request = API_URL . "/1/$username/$listname/members." . $this->type . $qs;
727 return $this->objectify( $this->process($request) );
730 function listFollowers( $id, $cursor = false )
732 if( !in_array( $this->type, array( 'xml','json' ) ) )
735 $arr = explode('/', $id);
736 if (count($arr) != 2) return false;
742 $args['cursor'] = $cursor;
744 if( !empty( $args ) )
745 $qs = $this->_glue( $args );
747 $request = API_URL . "/1/$username/$listname/subscribers." . $this->type . $qs;
748 return $this->objectify( $this->process($request) );
751 function followList( $id )
753 if( !in_array( $this->type, array( 'xml','json' ) ) )
756 $arr = explode('/', $id);
757 if (count($arr) != 2) return false;
761 $request = API_URL . "/1/$username/$listname/subscribers." . $this->type;
762 return $this->objectify( $this->process($request, true) );
765 function unfollowList( $id )
767 if( !in_array( $this->type, array( 'xml','json' ) ) )
770 $arr = explode('/', $id);
771 if (count($arr) != 2) return false;
775 $request = API_URL . "/1/$username/$listname/subscribers." . $this->type;
776 return $this->objectify( $this->process($request, "DELETE") );
779 function createList( $name, $description, $isProtect)
781 if( !in_array( $this->type, array( 'xml','json' ) ) )
784 $mode = $isProtect ? "private" : "public";
787 $args['name'] = $name;
789 $args['description'] = $description;
791 $args['mode'] = $mode;
793 if( !empty( $args ) )
794 $qs = $this->_glue( $args );
796 $request = API_URL . "/$this->username/lists." . $this->type . $qs;
798 return $this->objectify( $this->process($request, true) );
801 function editList( $prename, $name, $description, $isProtect)
803 if( !in_array( $this->type, array( 'xml','json' ) ) )
806 $mode = $isProtect ? "private" : "public";
809 $args['name'] = $name;
811 $args['description'] = $description;
813 $args['mode'] = $mode;
815 if( !empty( $args ) )
816 $qs = $this->_glue( $args );
818 $request = API_URL . "/$this->username/lists/$prename." . $this->type . $qs;
820 return $this->objectify( $this->process($request, true) );
823 function deleteList( $id)
825 if( !in_array( $this->type, array( 'xml','json' ) ) )
828 $arr = explode('/', $id);
829 if (count($arr) != 2) return false;
833 $request = API_URL . "/$username/lists/$listname." . $this->type;
835 return $this->objectify( $this->process($request, "DELETE") );
839 function deleteListMember( $id, $memberid )
841 if( !in_array( $this->type, array( 'xml','json' ) ) )
844 $arr = explode('/', $id);
845 if (count($arr) != 2) return false;
851 $args['id'] = $memberid;
853 if( !empty( $args ) )
854 $qs = $this->_glue( $args );
856 $request = API_URL . "/$username/$listname/members." . $this->type . $qs;
858 return $this->objectify( $this->process($request, "DELETE") );
861 function addListMember( $listid, $memberid )
863 if( !in_array( $this->type, array( 'xml','json' ) ) )
868 $args['id'] = $memberid;
870 if( !empty( $args ) )
871 $qs = $this->_glue( $args );
873 $request = API_URL . "/$this->username/$listid/members." . $this->type . $qs;
874 return $this->objectify( $this->process($request, true) );
877 /* ---------- Retweet ---------- */
878 function getRetweeters($id, $count = false){
879 $url = "http://api.twitter.com/1/statuses/retweets/$id.$this->type";
881 $url .= "?count=$count";
883 return $this->objectify($this->process($url, $args));
886 function retweet($id){
887 $url = "http://api.twitter.com/1/statuses/retweet/$id.$this->type";
889 $args['post_method'] = true;
890 return $this->curl_process($url, $args);
893 function retweets($id, $count = false){
894 $url = "http://api.twitter.com/1/statuses/retweets/id.$this->type";
896 $url .= "?count=".($count > 100 ? 100 : $count);
898 return $this->curl_process($url);
901 function retweeted_by_me($page = false, $count = 20, $since_id = false, $max_id = false){
902 $url = "http://api.twitter.com/1/statuses/retweeted_by_me.$this->type";
905 $args['since_id'] = $since_id;
908 $args['max_id'] = $max_id;
911 $args['count'] = $count;
914 $args['page'] = $page;
916 $url .= $this->_glue($args);
917 return $this->curl_process($url);
920 function retweeted_to_me($page = false, $count = false, $since_id = false, $max_id = false){
921 $url = "http://api.twitter.com/1/statuses/retweeted_to_me.$this->type";
924 $args['since_id'] = $since_id;
927 $args['max_id'] = $max_id;
930 $args['count'] = $count;
933 $args['page'] = $page;
935 $url .= $this->_glue($args);
936 return $this->curl_process($url);
939 function retweets_of_me($page = false, $count = false, $since_id = false, $max_id = false){
940 $url = "http://api.twitter.com/1/statuses/retweets_of_me.$this->type";
943 $args['since_id'] = $since_id;
946 $args['max_id'] = $max_id;
949 $args['count'] = $count;
952 $args['page'] = $page;
954 $url .= $this->_glue($args);
955 return $this->curl_process($url);
958 /**** Twitese Method ****/
960 function rank( $page = false, $count = false )
964 $args['page'] = $page;
966 $args['count'] = $count;
967 $qs = $this->_glue( $args );
969 $request = TWITESE_API_URL . '/rank.' . $this->type . $qs;
971 return $this->objectify( $this->process($request) );
974 function browse( $page = false, $count = false )
978 $args['page'] = $page;
980 $args['count'] = $count;
981 $qs = $this->_glue( $args );
983 $request = TWITESE_API_URL . '/browse.' . $this->type . $qs;
985 return $this->objectify( $this->process($request) );
987 /**** API Rate Limit ****/
990 if( !in_array( $this->type, array( 'xml','json' ) ) )
992 $request = API_URL . '/account/rate_limit_status.' . $this->type;
993 return $this->objectify( $this->process($request) );
996 function ratelimit_status()
998 return $this->ratelimit();
1001 /**** Upload Photo ****/
1003 function twitgooUpload( $image ) {
1004 $postdata = array( 'media' => "@$image", 'username' => $this->username, 'password' => $this->password);
1005 $request = 'http://twitgoo.com/api/upload';
1006 $this->type = 'xml';
1007 return $this->objectify( $this->process( $request, $postdata ) );
1010 function imglyUpload( $image ) {
1011 $postdata = array( 'media' => "@$image", 'username' => $this->username, 'password' => $this->password);
1012 $request = 'http://img.ly/api/upload';
1013 $this->type = 'xml';
1014 $this->ssl_mode = 1;
1015 return $this->objectify( $this->process( $request, $postdata ) );
1018 /****** Tests ******/
1020 function twitterAvailable()
1022 if( !in_array( $this->type, array( 'xml','json' ) ) )
1025 $request = API_URL . '/help/test.' . $this->type;
1026 if( $this->objectify( $this->process($request) ) == 'ok' )
1033 /**** request method ****/
1034 function process($url,$postargs=false,$ssl_mode=0)
1039 $url = ( $this->suppress_response_code ) ? $url . '&suppress_response_code=true' : $url;
1040 $ch = curl_init($url);
1041 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
1043 if($postargs !== false)
1045 curl_setopt ($ch, CURLOPT_POST, true);
1046 curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
1047 if ($postargs === "DELETE") {
1048 curl_setopt ($ch, CURLOPT_POSTFIELDS, "_method=DELETE");
1053 if($this->username !== false && $this->password !== false)
1054 curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password );
1056 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1057 // curl_setopt($ch, CURLOPT_VERBOSE, 1);
1058 curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
1059 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl_mode);
1061 $response = curl_exec($ch);
1063 $this->responseInfo=curl_getinfo($ch);
1065 if(intval($this->responseInfo['http_code'] ) == 200)
1071 function curl_process($url, $postargs = false)
1073 $url = ( $this->suppress_response_code ) ? $url . '&suppress_response_code=true' : $url;
1074 $ch = curl_init($url);
1075 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
1077 if($postargs !== false)
1079 if(isset($postargs['post_method'])){
1080 curl_setopt ($ch, CURLOPT_POST, true);
1082 curl_setopt ($ch, CURLOPT_POST, true);
1083 curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
1084 if ($postargs === "DELETE") {
1085 curl_setopt ($ch, CURLOPT_POSTFIELDS, "_method=DELETE");
1090 if($this->username !== false && $this->password !== false)
1091 curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password );
1093 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
1094 curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
1095 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1096 curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
1097 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1099 $response = curl_exec($ch);
1101 $this->responseInfo = curl_getinfo($ch);
1104 if($response === false){
1107 if($this->type == 'xml'){
1108 return @simplexml_load_string($response);
1109 }else if($this->type == 'json'){
1110 return @json_decode($response);
1114 // Ôö¼Ó $api_type ²ÎÊý
1115 function objectify( $data )
1117 if($date === false){
1120 if( $this->type == 'json' ) {
1121 $result = @json_decode( $data );
1127 if (isset($result->error)) {
1128 if (substr_count($result->request, 'user_timeline') && $result->error == 'Not authorized') {
1133 else return $result;
1134 }else if( $this->type == 'xml' ){
1135 if( function_exists('simplexml_load_string') ) {
1136 $obj = @simplexml_load_string( $data );
1143 if (isset($obj->error) || !$obj) return false;
1150 function arrToStr($postargs) {
1152 foreach ($postargs as $key=>$value) {
1153 $post_str .= $key . "=" . $value . "&";
1155 $post_str = substr($post_str, 0,-1);
1159 function _glue( $array )
1162 foreach( $array as $key => $val ) :
1163 $query_string .= $key . '=' . rawurlencode( $val ) . '&';
1166 return '?' . substr( $query_string, 0, strlen( $query_string )-1 );