In my previous post, I show you how to use Windows Azure Datamarket to create a Bing Search Engine Position checker. I told you that for free account, you only have 5000 requests per month. Paid subscription has higher limit.
This time I’ll show you how to check your remaining monthly quota for all of your Windows Azure Datamarket subscription without logging in to Azure Datamarket. This is the main function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | error_reporting(E_ALL^E_NOTICE); function check_bing_quota($key) { $ret=array(); $context = stream_context_create(array( 'http' => array( 'request_fulluri' => true, 'header' => "Authorization: Basic " . base64_encode($key . ":" . $key) ) ) ); $end_point='https://api.datamarket.azure.com/Services/My/Datasets?$format=json'; $response=file_get_contents($end_point, 0, $context); $json_data=json_decode($response); foreach ($json_data->d->results as $res) { $ret[]=array( 'title'=>$res->Title, 'provider'=>$res->ProviderName, 'entry_point'=>$res->ServiceEntryPointUrl, 'remaining'=>$res->ResourceBalance ); } return $ret; } |
How to call it:
$ret=check_bing_quota('put_your_real_account_key_here'); |
Example result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | array(2) { [0]=> array(4) { ["title"]=> string(36) "Bing Search API – Web Results Only" ["provider"]=> string(4) "Bing" ["entry_point"]=> string(57) "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb" ["remaining"]=> int(4981) } [1]=> array(4) { ["title"]=> string(15) "Bing Search API" ["provider"]=> string(4) "Bing" ["entry_point"]=> string(54) "https://api.datamarket.azure.com/Data.ashx/Bing/Search" ["remaining"]=> int(4997) } } |
Fully working demo: http://demo.ahowto.net/bing_quota/
Notes: