Posts tagged with laravel

I want to use the Google Ads API to access Google Ads reports. As a preliminary step, we want to use the GoogleCustomerServiceClient to retrieve customer information.

$MMC_ID = <My MMC 10 digits number>; $credentialsIniPath = app_path('resources/credentials/google/google_ads_php.ini'); $oAuth2Credential = (new OAuth2TokenBuilder())     ->fromFile($credentialsIniPath)     ->build(); $googleAdsClient = (new GoogleAdsClientBuilder())     ->fromFile($credentialsIniPath)     ->withOAuth2Credential($oAuth2Credential)     ->build(); $customerServiceClient = $googleAdsClient->getCustomerServiceClient(); try {     $customer = $customerServiceClient->getCustomer(ResourceNames::forCustomer($MMC_ID)); } catch(GoogleAdsException $e) {     $this->error($e->getMessage()); } 

But it returns an error

Fault ------- Status code: 7 Details: The caller does not have permission Failure: {"errors":[{"errorCode":{"authorizationError":"DEVELOPER_TOKEN_NOT_APPROVED"},"message":"The developer token is not approved. Non-approved developer tokens can only be used with test accounts."}]} 

The account Oauth2 login that created MMC, MMC is a test account. In google_ads_php.ini, clientId, clientSecret, refreshToken, and developerToken are already filled in. The refreshToken has just been generated.

What should I check for in this one?

Thanks.

Illuminate\Contracts\Container\BindingResolutionException Unable to resolve dependency [Parameter #0 [ $customerId ]] in class App\Jobs\BudgetFetch

namespace App\Http\Controllers; use App\Jobs\BudgetFetch; use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\Lib\V3\GoogleAdsClientBuilder; use Illuminate\Support\Facades\DB; class APIController extends Controller{     public function index(){         $clients = DB::table('account_names')->pluck('code');         foreach($clients as $customerId) {             budgetFetch::dispatch($customerId);         }     } } 

The above is a simple controller I've put together to trigger another job which is;

namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\Lib\V3\GoogleAdsClientBuilder; class BudgetFetch implements ShouldQueue{     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;     /**      * Create a new job instance.      *      * @return void      */     public function __construct(){     }     /**      * Execute the job.      *      * @return void      */     public function handle($customerId){         $clientId = "xxxxxxxxxxxx";         $clientSecret = "xxxxxxxxxxx";         $refreshToken = "xxxxxxxxxxxxxxxxxx";         $developerToken = "xxxxxxxxxxxxxxxxxx";         $loginCustomerId = "xxxxxxxxxxx";         $oAuth2Credential = (new OAuth2TokenBuilder())             ->withClientId($clientId)             ->withClientSecret($clientSecret)             ->withRefreshToken($refreshToken)             ->build()         ;         $googleAdsClient = (new GoogleAdsClientBuilder())             ->withDeveloperToken($developerToken)             ->withLoginCustomerId($loginCustomerId)             ->withOAuth2Credential($oAuth2Credential)             ->build()         ;         $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();         $query = 'SELECT campaign.id, campaign.name, metrics.cost_micros, campaign_budget.amount_micros FROM campaign ORDER BY campaign.id';         /** @var GoogleAdsServerStreamDecorator $stream */         $stream =             $googleAdsServiceClient->searchStream($customerId, $query);         foreach ($stream->iterateAllElements() as $googleAdsRow) {             /** @var GoogleAdsRow $googleAdsRow */             $metrics = $googleAdsRow->getMetrics();             $id = $googleAdsRow->getCampaign()->getId()->getValue();             $name = $googleAdsRow->getCampaign()->getName()->getValue();             $spend = $googleAdsRow->getCampaignBudget()->getAmountMicros()->getValue();             $budget = $metrics->getCostMicrosUnwrapped();             if($spend >= $budget){                 DB::table('budget_alerts')->insert(                     ['campaign' => $id, 'hitBudget' => 1]                 );             };         }     } } 

The error at the top of the question is what I get from this, If I put the variable in __construct the same thing happens. I've run a php artisan clear-compiled which I found in another question similar and it didn't seem to fix anything.

I am trying to create a web application (backend is in PHP / Laravel), with this functionality

  1. user ads a valid gmail address
  2. system checks if the address is valid and if such a address is assigned to a Google Ads Account
  3. if true, system should "somehow" retrieve the customerId of the google ads account, or all of them if there are more than one accessible from the address
  4. system checks if the ads account is an MCC account step
  5. if so, system should list all of the customers the mcc account is "handling" ...

My question is - how do I do step 3?

The "input" data I have is the e-mail address, at this point I already know that it's valid, and the account has already given permission to my application to access google ads, I have everything properly configured, but

I have no clue HOW to do it. The official API documentation is not very helpful, just like the official PHP library which I'm using, it assumes that I KNOW the customerId (or the loginCustomerId in the case of MCC accounts).

Any clue how could I do it?