Google Analytics Management API 500 Internal Serve

2019-07-27 11:40发布

I have an application which gets Google Analytics metadata and statistics for a couple dozens google users from Management and Reporting API.

Everything was ok for a long period (several month), but yesterday around 21:00 pm UTC one of them (user) started getting this error: 500, Backend Error or sometimes InternalError

His Management API requests:
get all Accounts response is 200 with with 360 items
get all WebProperties response is 200 with 170 items
get all Profiles response is 200 with 1000 items
get all Goals response is 500 with error [should be 1000 items, but error now]

And still getting this error for now (More than 24 hours).

By the way, Reporting API for this client works fine too (for one of his view/profile)

What i researched:
I've tried to request goals not for all, but for one specific account > specific property > specific profile, and api response is 200 OK! in this case!
Earlier request goals for all profiles worked fine, for a long period! But not today.

3条回答
迷人小祖宗
2楼-- · 2019-07-27 11:54

The problem was resolved by google team on their side! Thank you!

查看更多
爷的心禁止访问
3楼-- · 2019-07-27 11:55

So on a hunch I found a solution that seems to work. This would fail (very simplified):

var goalsList = analytics.Management.Goals.List("~all", "~all", "~all");
var goalsResult = goalsList.Execute();

That all, all, all reminded me of some problem I had on our platform. So I tried to limit my goal requests a bit. The first is accountId so I got all of our accounts and then looped over them pulling the set of goals for each.

This seems to work.

...
var accountIds = GetAccountIds(analytics); 
foreach (var a in accountIds)
{
     do
     {
         var goalsList = analytics.Management.Goals.List(a, "~all", "~all");
...
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-07-27 12:13

500 and 503 errors are basically sever load errors. The server that is processing your request took to long to process your request so it timed out. You need to remember that you are not the only one accessing a server. It could very easily be something that another developer was running that slowed down your request and resulted in an error.

You should implement exponential backoff and just try the request again.

Top tip: would be to not run on the hour you are competing with everyone that has a cron job set to run. Also running at midnight west cost USA is when everyone's quotas reset also a not a good time to be hitting the server.

Update:

The team would like to suggest that you post an issue on the issue tracker here. The management API team can have a look at it. Add your account info from Google Developer console. I would add the profile in question. Link the issue back here and I will send it to them.

If you are running the following request I think you should stop that's really not meant for returning huge numbers.

analytics.Management.Goals.List("~all", "~all", "~all");
查看更多
登录 后发表回答