Google ads PHP REST API call with Test account is returning UNAUTHENTICATED

56 views
Skip to first unread message

Amit

unread,
Apr 16, 2020, 4:27:15 PM4/16/20
to AdWords API and Google Ads API Forum
Hi. 

I am using Google Ads using PHP REST API call. 

Problem
I wish to retrieve the campaign and its metrics of Google Ads using PHP REST API call. 
I am following the steps explained below. 
I furnish the code below. 
I have copied the error below. 

Please help me to resolve the issue. 

Steps
1. I am working for my client. He has created a Test account for me. 
2. I am using a separate gmail account to sign in into this test account. 
3. After login I found the text "Test Account" on top right corner, in white color with red background. 
4. It has an account id in this format xxx-xxx-xxxx. I am using this account id as the CUSTOMER ID in the URL of REST API call. I am using it after removing the dash "-" from it. 
5. I have created a new user with a new personal Gmail id from Tools & Settings > Setup > Account access. I have received the email and authorize it. 

Questions
1. Please let me know whether the above steps are correctly followed. Please advice if I missed something. 

Code
$params = [
    "query" => "SELECT campaign.name, campaign.status, segments.device, 
                metrics.impressions, metrics.clicks, metrics.ctr, 
                metrics.average_cpc, metrics.cost_micros 
                FROM campaign 
                WHERE segments.date DURING LAST_30_DAYS", 
    "token-type" => "Bearar",
    "Authorization" => session()->get('access_token_googleads'),
    "developer_token" => "xxxxx",
    "response_type" => "code", 
    "access_type" => "offline", 
    "client_id" => "xxxxx", 
    "callback_url" => "http://localhost:8000/googleads/profile", 
    "refresh_token" => "xxxxx",  
];
$response = $this->curl($url, http_build_query($params), "application/json", false, false);
echo "<pre>";
print_r($response);

Error
{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

I am waiting for earliest reply. 


Regards & Thanks,
Amit 

Google Ads API Forum Advisor Prod

unread,
Apr 17, 2020, 3:03:30 AM4/17/20
to ala...@nuundigital.com, adwor...@googlegroups.com

Hi Amit,

Thank you for reaching out to Google Ads API support.

> Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.

You seem to have an authentication issue with your OAuth 2 access token. Please follow the instructions here to ensure that you can correctly make your API call with the correct authentication: https://developers.google.com/adwords/api/docs/guides/first-api-call#php_1

Hope that this helps your issue, thank you.



ref:_00D1U1174p._5001UZYZCD:ref

Amit

unread,
Apr 17, 2020, 7:33:11 AM4/17/20
to AdWords API and Google Ads API Forum
Hi. 

I am already authenticated using Login program using PHP, as suggested in the guide. I am correctly getting the access token. I am sharing the code where the error occurs. Please help me to resolve the issue. 

Regards.

Google Ads API Forum Advisor Prod

unread,
Apr 17, 2020, 9:57:37 AM4/17/20
to ala...@nuundigital.com, adwor...@googlegroups.com
Hi Amit,

Thank you for your reply and explaining that you have managed to authenticate and retrieve the access token.

If you are using PHP (or any of our client libraries), it is not necessary and we do not recommend using cURL to retrieve campaign details and metrics.

Instead, you should refer to our Get Campaigns code example for PHP, where we demonstrate how to use $googleAdsServiceClient->searchStream(...) to run the GAQL query. You can replace the GAQL query in our code example with your desired query.

i.e.
$query = 
'SELECT campaign.name, campaign.status, segments.device, 
  metrics.impressions, metrics.clicks, metrics.ctr, 
  metrics.average_cpc, metrics.cost_micros 
FROM campaign 
WHERE segments.date DURING LAST_30_DAYS';

Hope that this helps your issue, thank you.
 


ref:_00D1U1174p._5001UZYZCD:ref
Reply all
Reply to author
Forward
0 new messages