试用 twitter 和 sina 微博的 api 服务

posted on 2010-03-22 19:32:28+08:00 by david
http://wangblog.org/2010/03/twitter-sina-api.html
  1. <?php
  2. header('Content-type: text/html; charset=utf-8');
  3. /* 所有都是utf-8字符的 */
  4.  
  5. $d = getApi('http://twitter.com/users/show/wangblog.json');
  6. /* wangblog的用户信息 */
  7.  
  8. //$d = getApi('http://twitter.com/statuses/friends_timeline.json', 'user:pass');
  9. /* wangblog的所有Following用户的最新信息 */
  10.  
  11. //$d = getApi('http://twitter.com/statuses/update.json', 'user:pass', 'status='.urlencode('test twitter\'s api.'));
  12. /* 发表微博给twitter */
  13.  
  14. //$d = getApi('http://api.t.sina.com.cn/statuses/update.json', 'user:pass', 'source=2924220432&status='.urlencode('test sina\'s api.'));
  15. /* 发表微博给sina,其中 source 是用的分享按钮的 */
  16.  
  17. function getApi($url, $userpass=null, $data=null){
  18. $curl = curl_init();
  19. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  20. if($userpass){
  21. curl_setopt($curl, CURLOPT_USERPWD, $userpass);
  22. }
  23. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  24. curl_setopt($curl, CURLOPT_HEADER, 0);
  25. if($data){
  26. curl_setopt($curl, CURLOPT_POST, 1);
  27. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  28. }
  29. curl_setopt($curl, CURLOPT_URL, $url);
  30. $cdata = curl_exec($curl);
  31. $cheaders = curl_getinfo($curl);
  32. if(200 == $cheaders['http_code']){
  33. return $cdata;
  34. }else{
  35. print_r($cheaders);
  36. exit;
  37. }
  38. }
  39.  
  40. print_r(json_decode($d));
  41. ?>

Comments

posted on 2010-05-12 22:20:29+08:00 by david
http://t.qq.com/invite/0038b5edcf8fb5f78ba3

http://t.qq.com/invite/fb1821a1e4f866c9b66b

http://t.qq.com/invite/cea4746448995dcf003b

http://t.qq.com/invite/0a67c80f0401efbc440b

http://t.qq.com/invite/3c1236a9eb2ce62a096f

http://t.qq.com/invite/abe5a875669db2eb17df

http://t.qq.com/invite/d28187364a8b16d7b2d5

http://t.qq.com/invite/1618e92eba49ca1f8765

http://t.qq.com/invite/0b09b7a57288b42dd963
posted on 2010-05-16 02:48:31+08:00 by david
http://t.qq.com/invite/c43ac2047dd7921e0329

http://t.qq.com/invite/61fc14f1ec11f527e387

http://t.qq.com/invite/7400fd088ac9312dcdcd

http://t.qq.com/invite/03761a30df229ecc15ff

http://t.qq.com/invite/b12c93e7bb0c87e80e6d
posted on 2010-05-22 21:40:38+08:00 by david
http://t.qq.com/invite/5d047e21d7dd965ea7a3

http://t.qq.com/invite/368ad925beea3659609b

http://t.qq.com/invite/c91590571c7be375e9e3

http://t.qq.com/invite/547713c908b6c3120a23

http://t.qq.com/invite/3f42bc5a5d2b49f8f6bd
posted on 2010-05-24 11:16:38+08:00 by david
http://t.qq.com/invite/2c9b2c35ac61f3c37875

http://t.qq.com/invite/3ed77a5c97382dac4d9d

http://t.qq.com/invite/caf66a95b4714b2473cd

http://t.qq.com/invite/b21f1255ea9317406fdd

http://t.qq.com/invite/242fc17ea8940361f329

http://t.qq.com/invite/bba33814d098e1fe5f79

http://t.qq.com/invite/cba501ca4b400feaedb7

http://t.qq.com/invite/2a72ec5f41ea0c1c79c1

http://t.qq.com/invite/f38e0a366fdb002069a3

http://t.qq.com/invite/51f5ef36444531094e85
posted on 2010-05-25 22:21:49+08:00 by david
http://t.qq.com/invite/3ed77a5c97382dac4d9d

http://t.qq.com/invite/caf66a95b4714b2473cd

http://t.qq.com/invite/b21f1255ea9317406fdd

http://t.qq.com/invite/242fc17ea8940361f329

http://t.qq.com/invite/bba33814d098e1fe5f79

http://t.qq.com/invite/cba501ca4b400feaedb7

http://t.qq.com/invite/2a72ec5f41ea0c1c79c1

http://t.qq.com/invite/09a1bc7161434d47d1eb

http://t.qq.com/invite/b5f782e57921e70fbe3b

http://t.qq.com/invite/851397ea0245b715691f

http://t.qq.com/invite/0b9dd102a278ee0c31b1

http://t.qq.com/invite/9b74983db6fa9451c9ff

http://t.qq.com/invite/868ccae872a6a12cc3e3

http://t.qq.com/invite/8b0aa888bb4db0109fd3

All Code Snippets

Hot Code Snippets

New Code Snippets