使用新浪微博API的OAuth认证发布微博

来源:互联网 发布:自动分辨率软件 编辑:程序博客网 时间:2024/05/20 12:51

我们已经将用户新浪微博的oauth_token和oauth_secret保存到

$_SESSION['oauth_token']=$result['oauth_token'];
$_SESSION['oauth_secret']=$result['oauth_secret'];

里面,现在要做的就很简单了··就是调用sinaOauth的类进行发布。。

代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Statuses/update
$c = new WeiboClient( WB_AKEY ,
           WB_SKEY ,
           $_SESSION['last_key']['oauth_token'] ,
           $_SESSION['last_key']['oauth_token_secret'] );
 
$msg = $c->update("测试发表微博");
if ($msg === false ||$msg === null){
  echo"Error occured";
  returnfalse;
}
if (isset($msg['error_code']) && isset($msg['error'])){
  echo('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] );
  returnfalse;
}
echo($msg['id']." : ".iconv('UTF-8','GB2312',
$msg['text'])." - ".$msg["created_at"]);