Account/rate limit status

跳转到: 导航, 搜索
(创建新页面为 '== account/rate_limit_status == Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour. Calls to rate…')
 
 
(未显示7个用户的23个中间版本)
第1行: 第1行:
== account/rate_limit_status ==
+
{{api_desc2|
Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour. Calls to rate_limit_status do not count against the rate limit.  If authentication credentials are provided, the rate limit status for the authenticating user is returned.  Otherwise, the rate limit status for the requester's IP address is returned. Learn more about the REST API rate limiting.
+
uri=account/rate_limit_status|
 
+
desc=获取API的访问频率限制。返回当前小时内还能访问的次数。频率限制是根据用户请求来做的限制,具体细节参见:[[Rate-limiting|接口访问权限说明]]。|
=== URL: ===
+
format=XML/JSON|
http://api.t.sina.com.cn/account/rate_limit_status.format
+
httpMethod=GET|
+
needAuth=true|
===Formats:===
+
rateLimit=true|
xml, json
+
params=|
+
getParam=|
=== HTTP Method(s): ===
+
postParam=|
GET
+
result=
+
===XML示例===
===Requires Authentication (about authentication):===
+
<pre>
true, to determine a user's rate limit status
+
<?xml version="1.0" encoding="UTF-8"?>
false, to determine the requesting IP's rate limit status
+
 
+
===API rate limited (about rate limiting):===
+
false
+
 
+
===Geolocation [COMING SOON]:===
+
The <user> object contains the geo_enabled flag which, by default is false for all users. For more information, see the statuses/update method for more information.
+
+
===Response (about return values): ===
+
XML example (truncated):
+
<?xml version="1.0" encoding="UTF-8"?>
+
 
  <hash>
 
  <hash>
   <remaining-hits type="integer">19933</remaining-hits>
+
   <remaining-hits type="integer">150</remaining-hits>
   <hourly-limit type="integer">20000</hourly-limit>
+
   <hourly-limit type="integer">150</hourly-limit>
   <reset-time type="datetime">2009-04-08T21:57:23+00:00</reset-time>
+
   <reset-time-in-seconds type="integer">1264994233</reset-time-in-seconds>
   <reset-time-in-seconds type="integer">1239227843</reset-time-in-seconds>
+
   <reset-time type="datetime">Mon Feb 01 03:15:22 +0800 2010</reset-time>
 
  </hash>
 
  </hash>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
{
 +
  "hourly_limit":150,
 +
  "reset_time_in_seconds":1264994122,
 +
  "reset_time":"Mon Feb 01 03:15:22 +0800 2010",
 +
  "remaining_hits":150
 +
}
 +
</pre>|
 +
useAge=无|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
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示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>
 +
代码示例如下:
 +
<pre>
 +
//account/rate_limit_status
 +
//获取当前用户API访问频率限制
 +
$c = new WeiboClient( WB_AKEY ,
 +
                      WB_SKEY ,
 +
                      $_SESSION['last_key']['oauth_token'] ,
 +
                      $_SESSION['last_key']['oauth_token_secret']  );
  
===Usage examples: ===
+
$msg = $c->oauth->get("http://api.t.sina.com.cn/account/rate_limit_status.json");
cURL (about cURL):
+
if ($msg === false || $msg === null){
 
+
echo "Error occured";
curl -u user:password http://api.t.sina.com.cn/account/rate_limit_status.xml
+
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>
 +
}}

2012年3月20日 (二) 14:14的最后版本

目录

account/rate_limit_status

获取API的访问频率限制。返回当前小时内还能访问的次数。频率限制是根据用户请求来做的限制,具体细节参见:接口访问权限说明

URL

http://api.t.sina.com.cn/account/rate_limit_status.(json%7Cxml)

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

true
关于授权机制,参见授权机制声明

请求数限制

true
关于请求数限制,参见接口访问权限说明

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)

注意事项

返回结果

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
}

其他

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示例

请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:

//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']);
}
文档更新时间: 2012-03-20