Heim  >  Artikel  >  Backend-Entwicklung  >  使用新浪微博API的OAuth认证发布微博实例_php实例

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

WBOY
WBOYOriginal
2016-06-07 17:13:361045Durchsuche

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

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

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn