$o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$keys = array();
$keys['username'] = $_REQUEST['username'];
$keys['password'] = $_REQUEST['password'];
try {
$token = $o->getAccessToken('password', $keys);
} catch (OAuthException $e) {
echo json_encode(array('error' => $e->getMessage()));
}
if ($token) {
$c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']);
//如果Post中带有since_id
if (is_numeric($_REQUEST['since_id']) && !empty($_REQUEST['since_id'])) {
//获得比since_id更晚的mention
//API:{@link http://open.weibo.com/wiki/2/statuses/mentions statuses/mentions}
$atme = $c->mentions(1, NULL, $_REQUEST['since_id'], 0);
} else {
//没有since_id
$atme = $c->mentions(1, NULL, NULL, 0);
}
//若指定since_id,倒序排列获得的mentions数组,第一组即是since_id的后一条
//若未指定since_id,就不用倒序,直接获取最新一条
if (is_numeric($_REQUEST['since_id']) && !empty($_REQUEST['since_id'])) {
rsort($atme[statuses], SORT_STRING);
}
if (isset($atme[error])) {
echo json_encode($atme);
} else {
if (isset($atme[statuses][0])) {
//构造json
$new_atme = array('id' => $atme[statuses][0][id], 'text' => $atme[statuses][0][text], 'uid' => $atme[statuses][0][user][id], 'user' => $atme[statuses][0][user][screen_name]);