特定のプロファイルに到達するまで Google アナリティクス アカウントをループする Apps Script があります。
if (profileItems[i].getName() == "Dev Test" )
別の関数 (以下を参照) よりも、Google アナリティクス API を呼び出すと、常に例外がスローされます: Exception: Quota Error: User Rate Limit Exceeded
function getReportDataForProfile(profileId) {
var tableId = 'ga:' + profileId;
var startDate = getLastNdays(14); // 2 weeks (a fortnight) ago.
var endDate = getLastNdays(0); // Today.
var optArgs = {
'dimensions': 'ga:keyword', // Comma separated list of dimensions.
'sort': '-ga:visits,ga:keyword', // Sort by visits descending, then keyword.
'segment': 'dynamic::ga:isMobile==Yes', // Process only mobile traffic.
'filters': 'ga:source==google', // Display only google traffic.
'start-index': '1',
'max-results': '250' // Display the first 250 results.
};
//
//Exponential Backoff
//
for (var n=0; n<6; n++) {
try {
var results = Analytics.Data.Ga.get(
tableId, // Table id (format ga:xxxxxx).
startDate, // Start-date (format yyyy-MM-dd).
endDate, // End-date (format yyyy-MM-dd).
'ga:visits,ga:pageviews', // Comma seperated list of metrics.
optArgs);
} catch(e) {
if (n == 5) {
//var results = e;
//throw new Error('Quota ERROR');
throw (e)
}
Utilities.sleep((Math.pow(2,n)*1000) + (Math.round(Math.random() * 1000)));
}
}
return results;
}
- API コンソールのユーザーごとの制限の数を 10.0 に増やしました
- 使用される割合は 6% です
- そして、指数バックオフを適用しました
- また、Visits と PageViews を要求するだけで、コール数を誇張しているとは思いません。
何が起こっているのですか?