PHP code example of littlemo / weibo
1. Go to this page and download the library: Download littlemo/weibo library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
littlemo / weibo example snippets
use littlemo\weibo\Oauth2;
$Oauth2 = new Oauth2($client_id, $client_secret);
$result = $Oauth2->access_token($code, $redirect_uri);
if ($result) {
echo '获取Access token成功';
$token = $Oauth2->getMessage();
} else {
echo "获取Access token失败";
$errorMsg = $Oauth2->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\Oauth2;
$Oauth2 = new Oauth2();
$result = $Oauth2->get_token_info($access_token);
if ($result) {
echo '获取token info成功';
$token = $Oauth2->getMessage();
} else {
echo "获取token info失败";
$errorMsg = $Oauth2->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\Oauth2;
$Oauth2 = new Oauth2();
$result = $Oauth2->revokeoauth2($access_token);
if ($result) {
echo '回收成功';
$token = $Oauth2->getMessage();
} else {
echo "回收失败";
$errorMsg = $Oauth2->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\User;
$User = new User();
$result = $User->show($access_token, $uid , $screen_name);
if ($result) {
echo '获取用户信息成功';
$token = $User->getMessage();
} else {
echo "获取用户信息失败";
$errorMsg = $User->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\User;
$User = new User();
$result = $User->domain_show($access_token, $domain);
if ($result) {
echo '获取用户资料成功';
$token = $User->getMessage();
} else {
echo "获取用户资料失败";
$errorMsg = $User->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\JsApi;
$JsApi = new JsApi($client_id, $client_secret);
$result = $JsApi->ticket($access_token, $domain);
if ($result) {
echo '获取 ticket 成功';
$token = $JsApi->getMessage();
} else {
echo "获取 ticket 失败";
$errorMsg = $JsApi->getErrorMsg();
}
//查询完整的回调消息
$intactMsg = $Class->getIntactMsg();
use littlemo\weibo\JsApi;
$JsApi = new JsApi($client_id);
$result = $JsApi->signature($jsapi_ticket, $noncestr, $timestamp, $url, $client_id);
[
'appkey' => $client_id,
'timestamp' => $timestamp,
'noncestr' => $noncestr,
'signature' => $result,
'url' => $url,
];