摘要:继续前面的文章《新浪微博OAuth认证和储存的主要过程详解》,现在我们就使用它来发布微博。我们已经将用户新浪微博的oauth_token和oauth_secret保存到$_SESSION['oauth_token']=$result['oauth_token'];$_SESSION['oauth_secret']=$result['oauth
继续前面的文章《新浪微博OAuth认证和储存的主要过程详解》,现在我们就使用它来发布微博。
我们已经将用户新浪微博的oauth_token和oauth_secret保存到
$_SESSION['oauth_token']=$result['oauth_token'];
$_SESSION['oauth_secret']=$result['oauth_secret'];
里面,现在要做的就很简单了··就是调用sinaOauth的类进行发布。。
代码如下:
//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";
return false;
}
if (isset($msg['error_code']) && isset($msg['error'])){
echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] );
return false;
}
echo($msg['id']." : ".iconv('UTF-8', 'GB2312',
$msg['text'])." - ".$msg["created_at"]);更多关于使用新浪微博API的OAuth认证发布微博实例请关注PHP中文网(www.php.cn)其他文章!