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

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

WBOY
WBOYOriginal
2016-07-13 09:59:48876browse

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

 继续前面的文章《新浪微博OAuth认证和储存的主要过程详解》,现在我们就使用它来发布微博。

我们已经将用户新浪微博的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";

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了····

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

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/975132.htmlTechArticle使用新浪微博API的OAuth认证发布微博实例 继续前面的文章《新浪微博OAuth认证和储存的主要过程详解》,现在我们就使用它来发布微博。 我...
Statement:
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