Google Analytics throws 403 error

前端 未结 3 590
無奈伤痛
無奈伤痛 2021-01-22 02:01

I am attempting to download metric data from Google Analytics using C# and am performing user authentication with OAuth 2.0. I\'m using the Installed Application autho

相关标签:
3条回答
  • 2021-01-22 02:16

    //Thanks for this post. The required profile id can be read from the account summaries.

    Dictionary profiles = new Dictionary();

            var accounts = service.Management.AccountSummaries.List().Execute();
            foreach (var account in accounts.Items)
            {
                var profileId = account.WebProperties[0].Profiles[0].Id;
    
                profiles.Add("ga:" + profileId, account.Name);
            }
    
    0 讨论(0)
  • 2021-01-22 02:37

    This can help : https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors, look error 403.

    0 讨论(0)
  • 2021-01-22 02:38

    If auth seems to be working working then my suggestion is that you make sure you're providing the correct ID because based on your code snippet:

    var request = service.Data.Ga.Get(AccountID, StartDate, EndDate, Metrics);
    

    one can only assume that you're using the Account ID. If so, that is incorrect and you'd receive the error you've encountered. You need to query with the Profile ID.

    If you login to Google Analytics using the web interface you'll see the following pattern in URL of the browser's address bar:

    /a12345w654321p9876543/
    

    The number following the p is the profile ID, so 9876543 in the example above. Make sure you're using that and actually you should be using the table id which would be ga:9876543.

    If it isn't an ID issue then instead query the Management API to list accounts and see what you have access to and to verify auth is working correctly.

    0 讨论(0)
提交回复
热议问题