Publish Weibo instance using OAuth authentication of Sina Weibo API
Continue with the previous article "Detailed explanation of the main process of Sina Weibo OAuth authentication and storage", now we will use it to post on Weibo.
We have saved the oauth_token and oauth_secret of user Sina Weibo to
$_SESSION['oauth_token']=$result['oauth_token'];
$_SESSION['oauth_secret']=$result['oauth_secret'];
Inside, what you have to do now is very simple...just call the sinaOauth class to publish. .
The code is as follows:
?
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"]);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1516
17
|
//Statuses/update
$c = new WeiboClient( WB_AKEY ,
WB_SKEY ,
$_SESSION['last_key']['oauth_token'] ,
$_SESSION['last_key']['oauth_token_secret'] );
$msg = $c->update("Test publish on Weibo");
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"]);
|
This is the simplest one...
The above is the entire content of this article, I hope you all like it.
Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!
http://www.bkjia.com/PHPjc/975132.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975132.htmlTechArticlePublish Weibo instance using OAuth authentication of Sina Weibo API Continue with the previous article "Sina Weibo OAuth Authentication and Storage "Detailed explanation of the main process", now we will use it to publish Weibo. I...