Getting oauth token http header is malformed

480 views
Skip to first unread message

Chris Lin

unread,
Mar 18, 2024, 5:11:26 AM3/18/24
to Google Ads API and AdWords API Forum
Been trying to make a simple campaign reports using PHP/Laravel, tried to follow docs and search on Google but running into a wall. Is there a way to find out what the actual headers are being sent? I pieced together the code from the help docs and random google searches, feels like I am missing something basic?

The error is below:
  -metadata: array:1 [
    0 => array:3 [
      "@type" => "type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure"
      "errors" => array:1 [
        0 => array:2 [
          "errorCode" => array:1 [
            "authenticationError" => "OAUTH_TOKEN_HEADER_INVALID"
          ]
          "message" => "Oauth token HTTP header is malformed."
        ]
      ]
      "requestId" => "eZJRtqwznPOdfR-5M_9sgA"
    ]
  ]

  $oAuth2Credential = (new OAuth2TokenBuilder())
                ->fromFile(storage_path('google_ads_php.ini'))
                ->build();

            $googleAdsClient = (new GoogleAdsClientBuilder())

                ->fromFile(storage_path('google_ads_php.ini'))
                ->withOAuth2Credential($oAuth2Credential)
                ->withDeveloperToken(env('GOOGLE_DEVELOPER_KEY'))
                ->withLoginCustomerId($this->managerCustomerId)
                ->build();
            $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
            $response = $googleAdsClient->getGoogleAdsServiceClient()->searchStream(
                SearchGoogleAdsStreamRequest::build($customerId, $query)
            );

Chris Lin

unread,
Mar 18, 2024, 6:27:31 PM3/18/24
to Google Ads API and AdWords API Forum
I just cloned this app https://github.com/googleads/google-ads-php/tree/main/examples/LaravelSampleApp and set it up and get the same error. Is it possible it's my google_ads_php.ini? I left the contents of it below with the credentials masked out, one of the requestIds was "e87P3kSbIgA-m-oFOB325Q"

[GOOGLE_ADS]
developerToken = "XXXXXXXXXXX"
loginCustomerId = "XXXXXXXXXXX"

[OAUTH2]
; For service account flow.
jsonKeyFilePath = "VALID PATH TO JSON"
scopes = "https://www.googleapis.com/auth/adwords"
impersonatedEmail = "x...@xxx.xxx"

Chris Lin

unread,
Mar 20, 2024, 12:18:00 AM3/20/24
to Google Ads API and AdWords API Forum
Solved it, developer key was incorrectly typed in

Google Ads API Forum Advisor

unread,
Mar 20, 2024, 6:14:13 AM3/20/24
to dontann...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for contacting the Google Ads API support team.

Please feel free to get back to us if you need any further assistance related to Google Ads API.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02s05Oq:ref" (ADR-00227949)

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages