Posts tagged with php

We have an app with offline access_type token. Yesterday all queries were broken, because authorization failed

POST https://oauth2.googleapis.com/token 

resulted in a

400 Bad Request response: { "error": "invalid_grant", "error_description": "Bad Request" }).

We use SDK Google Ads API Client Library for PHP for any queries to API.

Code example:

// Generate a refreshable OAuth2 credential for authentication.         $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile($filePathName)->build();         $loggerFactory    = new LoggerFactory();         $logger           = $loggerFactory->createLogger('TestChannel',             APPLICATION_DIRECTORY . ".log/google/adsapi.date("Y-m").".log",             'DEBUG');         // Construct a Google Ads client configured from a properties file and the         // OAuth2 credentials above.         $googleAdsClient = (new GoogleAdsClientBuilder())             ->fromFile(std::lpath($filePathName))             ->withOAuth2Credential($oAuth2Credential)             ->withLogger($logger)             ->build();         $query = "SELECT customer_client.status FROM customer_client";         $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();         $response               = $googleAdsServiceClient->search(             $customerId,             $query,             ['pageSize' => self::PAGE_SIZE]         );         return $response->getIterator()->current();

App is in production in google cloud console.

What have we already done:

  • changed password for account
  • reset secret and generate new refresh token

Create new app isn't good solution for us, because I think, we couldn't quickly increase limits to API (but in this moment we were forced to use an app with basic limits and quota)

Any idea how to solve this problem or how contact Google oAuth team with this question?

Related to https://groups.google.com/g/adwords-api/c/nvLa0xPkdUs/m/0P3LcxBgAQAJ

Update: I had found, that there is no link to my app in https://myaccount.google.com/permissions Anyone know, how to add this permissions again?

I am trying to use a service account to connect with the Google Ads API.

At the momet my code looks like this:

$oAuth2Credential = (new OAuth2TokenBuilder())         ->withJsonKeyFilePath(self::CREDENTIALS_FILE_PATH)         ->withScopes('https://www.googleapis.com/auth/adwords')         ->withImpersonatedEmail(IMPERSONATED_EMAIL)         ->build();     $googleAdsClient = (new GoogleAdsClientBuilder())         ->withOAuth2Credential($oAuth2Credential)         ->withDeveloperToken(DEVELOPER_TOKEN)         ->build();     $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();     $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';     $stream =         $googleAdsServiceClient->searchStream(CUSTOMER_ID, $query); 

In Google cloud I have created a project and a service account. The account is the same I have access to at Google Ads. Also I have set the Domain-Wide Delegation at Google Workspace, with this same account. In my opinion I did everything right, but I am getting this error:

I hope there's someone who can help me out.

I am sending message from Facebook whatsapp api to my number for testing. Message is sent from php but not recieved on mobile. Did I must register business on facebook?

{"messaging_product":"whatsapp","contacts":[{"input":"923040165804","wa_id":"923040165804"}],"messages":[{"id":"wamid.HBgMOTIzMDQwMTY1ODA0FQIAERgSOEM3RDJDRDMyMkFENkIzMTgyAA=="}]}

this php code that I am using.

        $curl = curl_init();         curl_setopt_array($curl, array(             CURLOPT_URL => 'https://graph.facebook.com/v13.0/********/messages/',             CURLOPT_RETURNTRANSFER => true,             CURLOPT_ENCODING => '',             CURLOPT_MAXREDIRS => 10,             CURLOPT_TIMEOUT => 0,             CURLOPT_FOLLOWLOCATION => true,             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,             CURLOPT_CUSTOMREQUEST => 'POST',             CURLOPT_POSTFIELDS =>json_encode(array("to"=> $number, "messaging_product" => 'whatsapp', "recipient_type" => 'individual',"type"=>"text", 'text'=> array('body'=>'hello_wo332233rld','preview_url'=>'false'))),             CURLOPT_HTTPHEADER => array(                 'Authorization: Bearer '.$chatApiToken,                 'Content-Type: application/json'             ),         ));         $response = curl_exec($curl);         curl_close($curl);         echo $response; 

I got this Fatal Error/Uncaught Error while linking with the Google Ads API. I've used the Github code and downloaded library from composer

Fatal error: Uncaught Error: Class "Google\Ads\GoogleAds\Examples\Utils\ArgumentParser" not found in googleAdword\examples\BasicOperations\GetCampaigns.php:44 Stack trace: #0 googleAdword\examples\BasicOperations\GetCampaigns.php(120): Google\Ads\GoogleAds\Examples\BasicOperations\GetCampaigns::main() #1

Tried all these solutions:

  1. reinstalling the lib, and not through zip downloading at first, but through git clone, and then install through composer etc.
  2. In the sample code of GetAccountInformation, there is a CUSTOMER_ID field that is required before you execute the code.(Already set)

I'm using the following lines of code (PHP) after successfuly retriving the media URL and then storing it in the $mediaURL variable for the file request, but it's returning an empty string. Already tried with postman and it returns a 500 internal server error...

** Edited **

self::writeLog('Media URL: '.$mediaURL); self::writeLog('Preparing to download media - id: '.$media_id); $curl = curl_init($mediaURL); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array(     "Authorization: Bearer ".self::$auth_token, ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); if (($resp = curl_exec($curl)) === false) {     self::writeLog('cURL Error: '.curl_error($curl)); } else if ($resp == '') {     self::writeLog('Empty string.');     self::writeLog('URL: '.$mediaURL);     self::writeLog('Headers: '.$headers[0]); } else {     self::writeLog($resp); }              
  • writeLog is just a method that I use to write these messages on a txt file.