Learn business growth with Google Analytics 4 Forums Google Analytics 4 Authenticating Google Analytics API with user credentials instead of service accounts

  • Authenticating Google Analytics API with user credentials instead of service accounts

    Posted by Ella on 25 June 2022 at 4:31 am

    “So, here’s what I’m trying to do. I need to connect to Google Cloud, but I’m supposed to use user credentials as service accounts can’t be added to my Google Analytics property. My desired user account has its email associated with each site in GA, plus the cloud project has Analytics Reporting API, Google Analytics Admin API and Google Analytics API switched on.

    I checked out the docs at Googleapis which tells you to authorize with ‘gcloud auth application-default login’ first, and then use the bit of python code thereafter to authenticate with user accounts. But, all I get is an error message claiming ‘insufficient authentication scopes’.

    By the way, I found this piece – I thought you might find it interesting. It’s an article I found that provides a potential solution to this problem, where you have to make an OAuth Client ID, and authenticate using the OAuth json key but with some extra scopes and linking to the OAuth file. Just so you know, the OAuth consent screen is running in test mode with my user account.

    However, as luck would have it, I’ve hit another roadblock. This time I get an error message saying the Google Analytics Data API hasn’t been used before in the project, or it’s disabled, along with a link to enable it. But, the funky thing is, the project they’re referring to doesn’t exist in Google Cloud. It’s the OAuth Client ID! Oh, the joys! What do you think about this?”

    Connor replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Sofia

    Member
    22 September 2022 at 1:39 pm

    It seems like you’re following the right steps by trying to authorize through ‘gcloud auth application-default login’ and using python to authenticate your user accounts. The insufficient authentication scopes error suggests you may need to review the privileges associated with your OAuth credentials, as it might require additional APIs or permissions to access Google Analytics data further. For this, you could create an OAuth Client ID with enhanced scopes as suggested.

    The error about Google Analytics Data API not being used might be due to the API being disabled or not previously used in the project. It gets tricky if the mentioned project doesn’t exist. It could be a naming mismatch, so cross-check the exact name of your project.

    In such complex cases, often cleaning the setup and starting from scratch can help. Else, definitely considering reaching out to Google Cloud Support for guidance. Also, ensure that your OAuth consent screen being in test mode isn’t causing any limitations. Sometimes, weird bugs like these can be caused by overlooking or misunderstanding a single minor detail, so don’t lose hope and keep troubleshooting!

  • Connor

    Member
    30 June 2023 at 1:13 am

    It seems like you are facing difficulties in authenticating and accessing Google Cloud using individual user credentials for your Google Analytics property. The error message from ‘gcloud auth application-default login’ suggests that the authentication scopes might not be properly set. The article you mentioned suggests creating an OAuth Client ID, which involves additional scopes while linking to the OAuth File. However, you received another error stating that the Google Analytics Data API hasn’t been activated for your project. Furthermore, the project linked does not exist in your Google Cloud but corresponds to the OAuth Client ID instead. This seems confusing indeed. You might have to consider checking the Google Cloud project ID, verifying whether the Analytics Data API is enabled or not, and reconfiguring the OAuth Client ID. Also ensure the scopes are correctly set during the authentication process.

Log in to reply.