Account/rate limit status
(→Java示例: 只能使用oauth登录) |
(→Java示例) |
||
第61行: | 第61行: | ||
} | } | ||
} | } | ||
+ | ====PHP示例==== | ||
+ | <pre> | ||
+ | //account/rate_limit_status | ||
+ | //获取当前用户API访问频率限制 | ||
+ | $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); | ||
+ | $msg = $c->oauth->get("http://api.t.sina.com.cn/account/rate_limit_status.json"); | ||
+ | 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; | ||
+ | } | ||
+ | if (isset($msg['hourly_limit'])){ | ||
+ | echo($msg['hourly_limit']); | ||
+ | } | ||
+ | </pre> |
2010年8月4日 (三) 14:09的版本
目录 |
account/rate_limit_status
关于API的访问频率限制。返回当前小时还能访问的次数。频率限制是根据用户请求来做的限制,具体可以参加频率限制说明。
URL:
http://api.t.sina.com.cn/account/rate_limit_status.format
格式:
xml, json
HTTP请求方法:
GET
是否需要登录:
true
调用频率限制:
false
返回:
XML 格式样例:
<?xml version="1.0" encoding="UTF-8"?> <hash> <remaining-hits type="integer">150</remaining-hits> <hourly-limit type="integer">150</hourly-limit> <reset-time-in-seconds type="integer">1264994233</reset-time-in-seconds> <reset-time type="datetime">Mon Feb 01 03:15:22 +0800 2010</reset-time> </hash>
JSON示例:
{"hourly_limit":150,"reset_time_in_seconds":1264994122, "reset_time":"Mon Feb 01 03:15:22 +0800 2010","remaining_hits":150}
使用示例:
curl -u user:password http://api.t.sina.com.cn/account/rate_limit_status.xml
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示例如下:
package weibo4j.examples.account; import weibo4j.RateLimitStatus; import weibo4j.Weibo; import weibo4j.WeiboException; public class GetRateLimitStatus { /** * 获取当前用户API访问频率限制 * @param args */ public static void main(String[] args) { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); try { Weibo weibo = new Weibo(); weibo.setToken(args[0], args[1]); RateLimitStatus limitStatus = weibo.rateLimitStatus(); System.out.println(limitStatus.toString()); } catch (WeiboException e) { e.printStackTrace(); } } }
PHP示例
//account/rate_limit_status //获取当前用户API访问频率限制 $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); $msg = $c->oauth->get("http://api.t.sina.com.cn/account/rate_limit_status.json"); 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; } if (isset($msg['hourly_limit'])){ echo($msg['hourly_limit']); }