Home > Backend Development > PHP Tutorial > 使用新浪微博API的OAuth认证发布微博实例_PHP

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

WBOY
Release: 2016-06-01 11:06:10
Original
867 people have browsed it

继续前面的文章《新浪微博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"]);

Copy after login

这样最简单的就OK了····

以上所述就是本文的全部内容了,希望大家能够喜欢。

请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template