Google Analytics throws 403 error

前端 未结 3 592
無奈伤痛
無奈伤痛 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: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.

提交回复
热议问题