+ -
当前位置:首页 → 问答吧 → 新浪微博API

新浪微博API

时间:2009-11-26

来源:互联网

复制代码
  1. <?php   
  2. /*  
  3. -------------------------------------------------------  
  4. @名称:基于CURL的新浪微博接口  
  5. @演示:http://demos.fengyin.name/apps/sina-microblog-api.php  
  6. @作者:风吟  
  7. @博客:http://fengyin.name/  
  8. @更新:2009年11月6日 17:15:54  
  9. @版权:Copyright (c) 风吟版权所有转载请保留注释,本程序为开源程序(开放源代码)。  
  10. 只要你遵守 MIT licence 协议.您就可以自由地传播和修改源码以及创作衍生作品.  
  11. -------------------------------------------------------  
  12. 调用方式:  
  13. sendmicroblog([帐号],[密码],[内容]);  
  14. */  
  15. function sendmicroblog($a, $b, $c) {   
  16.     $d = tempnam('./', 'cookie.txt'); //创建随机临时文件保存cookie.   
  17.     $ch = curl_init("https://login.sina.com.cn/sso/login.php?username=$a&password=$b&returntype=TEXT");   
  18.     curl_setopt($ch, CURLOPT_COOKIEJAR, $d);   
  19.     curl_setopt($ch, CURLOPT_HEADER, 0);   
  20.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   
  21.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
  22.     curl_setopt($ch, CURLOPT_TIMEOUT, 10);   
  23.     curl_setopt($ch, CURLOPT_USERAGENT, "FengYin");   
  24.     curl_exec($ch);   
  25.     curl_close($ch);   
  26.     unset($ch);   
  27.     $ch = curl_init($ch);   
  28.     curl_setopt($ch, CURLOPT_URL, "http://t.sina.com.cn/mblog/publish.php");   
  29.     curl_setopt($ch, CURLOPT_REFERER, "http://t.sina.com.cn");   
  30.     curl_setopt($ch, CURLOPT_POST, 1);   
  31.     curl_setopt($ch, CURLOPT_POSTFIELDS, "content=".urlencode($c));   
  32.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
  33.     curl_setopt($ch, CURLOPT_COOKIEFILE, $d);   
  34.     curl_exec($ch);   
  35.     curl_close($ch);   
  36.     unlink($d);//删除临时文件.   
  37.   
  38. }   
  39.   
  40. sendmicroblog('这里是帐号','这里是密码','测试一下新浪微博API,此条信息通过API发送');   
  41.   
  42. ?>   
  43.  

作者: uncleliu   发布时间: 2009-11-26

路过看一下。。。

作者: liuqzhi110   发布时间: 2009-11-27

路過看一下,收藏

作者: kahn178   发布时间: 2009-11-27

看一下!

作者: wangfubao   发布时间: 2009-11-27

很好,以前我也写过,

作者: studclub   发布时间: 2009-11-27

路過看一下,收藏

作者: tochenwei   发布时间: 2009-12-03

热门下载

更多