我想知道我该怎么做才能不对 API 进行多次调用?例如,如果我尝试使用 yelp 的 api,他们会在超出之前限制调用次数(一旦超出该数量,他们就会停止向您提供信息)。
我能做些什么?现在,我在从他们的网站获取信息所需的每个页面中都有这个(来自他们的 API PHP 示例):
// For example, request business with id 'the-waterboy-sacramento'
//$unsigned_url = "http://api.yelp.com/v2/business/the-waterboy-sacramento";
// For examaple, search for 'tacos' in 'sf'
//$unsigned_url = "http://api.yelp.com/v2/search?term=tacos&location=sf";
// My own code
$unsigned_url = "http://api.yelp.com/v2/search?term=".$term."";
// $term is coming from searching
// Set your keys here
$consumer_key = "some_id";
$consumer_secret = "some_id";
$token = "some_id";
$token_secret = "some_id";
// Token object built using the OAuth library
$token = new OAuthToken($token, $token_secret);
// Consumer object built using the OAuth library
$consumer = new OAuthConsumer($consumer_key, $consumer_secret);
// Yelp uses HMAC SHA1 encoding
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
// Sign the request
$oauthrequest->sign_request($signature_method, $consumer, $token);
// Get the signed URL
$signed_url = $oauthrequest->to_url();
// Send Yelp API Call
$ch = curl_init($signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch); // Yelp response
curl_close($ch);
当我想打电话给某个企业时,在每一页都这样做似乎有点过分。