google-ads-api icon indicating copy to clipboard operation
google-ads-api copied to clipboard

[Bug] listAccessibleCustomers function throws an unauthorized_client error

Open klausXR opened this issue 1 year ago • 4 comments

When trying to access accessible customers of a given refresh token, if the account is a manager account, google requires the login-customer-id parameter to be passed as described here

https://developers.google.com/google-ads/api/rest/auth#login_customer_id

However, this parameter is hardcoded in the service which has the listAccessibleCustomers in the code to be an empty string.

There should be a way to pass this optionally to that service so that the method works.

When I went through their REST API directly and passed in the parameter, everything worked as expected.

klausXR avatar Apr 04 '23 05:04 klausXR

@klausXR good find, we will look into this when we get the chance

wcoots avatar Apr 12 '23 10:04 wcoots

I am not sure how this could ever work, to even get a developer token to access the API, the google ads account HAS to be a manager account.. or am I misunderstanding something?

bobmoff avatar Aug 09 '23 16:08 bobmoff

Had to go around this too:

`export const getGoogleAdAccounts = onCall(async (req) => { const { data } = req;

try {
    const {tokens} = await getGoogleAdsTokens(data.brand$key);

    // Create an instance of the Google Auth Client
    const oauth2Client = new google.auth.OAuth2(
        process.env.GOOGLE_CLIENT_ID,
        process.env.GOOGLE_CLIENT_SECRET,
        "http://localhost:3000/callback" 
    );
    
    oauth2Client.setCredentials({
        refresh_token: tokens.refresh_token
    });

    // Get the access token
    const accessToken = await oauth2Client.getAccessToken();

    // Make a request to the Google Ads API
    const response = await fetch('https://googleads.googleapis.com/v8/customers', {
        headers: {
            'Authorization': `Bearer ${accessToken.token}`,
            'developer-token': process.env.GOOGLE_ADS_DEVELOPER_TOKEN
        }
    });

    const data = await response.json();
    return data.customers;
     
} catch(error) {
     logger.error(`Failed to get Google Ad accounts: ${error}`);
    throw new Error('Failed to get Google Ad accounts');
}

}) `

jobizzness avatar Oct 06 '23 02:10 jobizzness