googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
288 stars 260 forks source link

We lost data when update ad #948

Closed techshoppingiq closed 11 months ago

techshoppingiq commented 1 year ago

We use this library for update or create responsive search ads and we lost data which we manually set. Please see video and help us to fix. Thanks in advance.

Google\Ads\GoogleAds\Lib\V13\GoogleAdsClientBuilder; PHP V: 8.0.30 Video link: https://drive.google.com/file/d/1aK4legSfYmQ8TyvT3DQ2FmvpLFBOQnjE/view

fiboknacky commented 1 year ago

Could you please share the log of the request you sent to the API server?

techshoppingiq commented 1 year ago

We are also facing issue in getting logs. we are using below code, If you need log can you help us to fix this then.

// Generate a refreshable OAuth2 credential for authentication. $oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId($client_id) ->withClientSecret($client_secret) ->withRefreshToken($refresh_token) ->fromEnvironmentVariables() ->build();

        // OAuth2 credentials above.
        $googleAdsClient = (new GoogleAdsClientBuilder())
                ->withOAuth2Credential($oAuth2Credential)
                ->withDeveloperToken($developer_token)
                //->withLoginCustomerId($customerId)
                ->withLoginCustomerId($loginCustomerId)
                ->withTransport('rest')
                ->fromEnvironmentVariables()
                ->withLogger((new LoggerFactory())->createLogger(
                                'google-ads',
                                FCPATH . 'public/gads/ads.log',
                                'DEBUG'
                        ))
                ->build();
fiboknacky commented 1 year ago

Can you use google_ads_php.ini? That should be faster since you can just specify the path to the log file.

techshoppingiq commented 1 year ago

We are using this above code for multiple client ids dynamically, Can you guide use how we can use google_ads_php.ini,

fiboknacky commented 1 year ago

Please take a look at this guide. Let me know if you have questions.

techshoppingiq commented 1 year ago

We have create file as sibling of ini file and give path like this but we still not getting logs, Please help us to fix this. image

image

fiboknacky commented 1 year ago

So, you now see the file created but nothing in there? Or is the file.log created by yourself? If you wish to see the log created under your project directory (where you can find the vendor directory), you can just specify it as file.log.

techshoppingiq commented 1 year ago

file.log created by myself. I have check not log file found in vender folder. i have five full server path but still not get logs. Please help us to fix. image

fiboknacky commented 1 year ago

I cannot see your path in your server, so it'd be hard for me to figure this out too, but if you're sure that the path is correct, the next thing would be a permission. You need to set the write permission for the path.

I'd just start small by specify only file.log and see if the log is produced.

techshoppingiq commented 1 year ago

File have full permission what i am using for get log and path is also correct. We not have other way to get these details? We need it we are stuck in issue.

fiboknacky commented 1 year ago

Did you try what I suggested--using file.log? What happened?

techshoppingiq commented 1 year ago

Yes i tried it but till not get logs.

fiboknacky commented 1 year ago

Can you share how your project directory looks like? What code did you run? Are there any error messages? Or is it silent everywhere and the code just returned to the command prompt?

I'd recommend running something small (like our GetCampaigns) first.

techshoppingiq commented 1 year ago

Below is my directories and code

$oAuth2Credential = (new OAuth2TokenBuilder())
    ->fromFile(FCPATH . "public/clients/$userId/google_ads_php.ini")
    ->build();

$googleAdsClient = (new GoogleAdsClientBuilder())
    ->fromFile(FCPATH . "public/clients/$userId/google_ads_php.ini")
    ->withOAuth2Credential($oAuth2Credential)
    ->build();

$ad = new Ad([
    "resource_name" => ResourceNames::forAd($customerId, $resourceAdgroupAdId),
    "responsive_search_ad" => new ResponsiveSearchAdInfo([
        "headlines" => $headlines,
        "descriptions" => $descriptions,
    ]),
    "final_urls" => [$adLink],
    //'final_mobile_urls' => ['http://www.example.com/mobile']
]);

$adOperation = new AdOperation();
$adOperation->setUpdate($ad);
$adOperation->setUpdateMask(FieldMasks::allSetFieldsOf($ad));

$mutateAds[ResourceNames::forAd($customerId, $resourceAdgroupAdId)] = $adOperation;

$adServiceClient = $googleAdsClient->getAdServiceClient();
$response = $adServiceClient->mutateAds($customerId, $mutateAds);

image

techshoppingiq commented 1 year ago

image

fiboknacky commented 1 year ago

Are there any error messages? Or is it silent everywhere and the code just returned to the command prompt?

Could you also answer these questions? And how did you run the code, using a normal php command?

And from the latest image, I still see you use the full file path. Did you try what I suggested--using only file.log?

techshoppingiq commented 1 year ago

Yes i tried and after that try full server path. No i am not getting any error message. Code run fully and at the end get result from api using below code.

foreach ($response->getResults() as $updatedAd) { //$updatedAd = $response1->getResults(); echo "

UPDATED: $testResource

"; }

fiboknacky commented 1 year ago

If you comment out the logFilePath, do you get a log printed out on your screen?

techshoppingiq commented 12 months ago

Tried but not printed on screen.

image

fiboknacky commented 12 months ago

So, you ran the php <YOUR_FILE> on your server command prompt, right?

From what I see, it should already work. I don't have the full visibility to your server, so unfortunately, this is challenging. Any chance you can test this locally first? The config logLevel should already be enough to allow the library to print out at least the summary log.

techshoppingiq commented 12 months ago

No we have run very simple code but still not getting log on file or my screen. vender folder and my code in same file. Also test with and without logFilePath.

That is simplest code we can try only update single ad.

techshoppingiq commented 12 months ago

image

techshoppingiq commented 12 months ago

image

techshoppingiq commented 12 months ago

`<?php

require DIR . '/vendor/autoload.php';

use Google\Ads\GoogleAds\V13\Common\AdTextAsset; use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\Lib\V13\GoogleAdsClientBuilder; use Google\Ads\GoogleAds\V13\Resources\Ad; use Google\Ads\GoogleAds\Util\V13\ResourceNames; use Google\Ads\GoogleAds\V13\Common\ResponsiveSearchAdInfo; use Google\Ads\GoogleAds\V13\Services\AdOperation; use Google\Ads\GoogleAds\Util\FieldMasks;

$resourceAdgroupAdId = "673720332679";

function createAdTextAsset(string $text, int $pinField = null) { $adTextAsset = new AdTextAsset(['text' => $text]); if (!is_null($pinField)) { $adTextAsset->setPinnedField($pinField); } return $adTextAsset; }

$headlines = [ new AdTextAsset(['text' => ucwords('Complete Multivitamin Complex')]), new AdTextAsset(['text' => ucwords('8.24')]), new AdTextAsset(['text' => ucwords('In Stock')]), new AdTextAsset(['text' => ucwords("test headline 4")]), ];

$descriptions = [ new AdTextAsset(['text' => ucfirst("Formulated by top sports nutritionists to support the daily demands of an active lifestyle")]), new AdTextAsset(['text' => ucfirst("A multivitamin providing over 30 vitamins & minerals alongside fruit & plant extracts.")]), new AdTextAsset(['text' => ucfirst("Complete Multivitamin supports energy metabolism, immune function & amino acid synthesis.")]), new AdTextAsset(['text' => ucfirst("Perfect for anyone seeking a high-quality multivitamin supplement to complement their diet")]) ];

$customerId = 'xxxxxx';

$oAuth2Credential = (new OAuth2TokenBuilder()) ->fromFile(DIR . "/google_ads_php.ini") ->build();

$googleAdsClient = (new GoogleAdsClientBuilder()) ->fromFile(DIR . "/google_ads_php.ini") ->withOAuth2Credential($oAuth2Credential) ->build(); $adLink = "https://www.bulk.com/uk/complete-multivitamin-complex.html"; // Update ad which already exits.. $ad = new Ad([ 'resource_name' => ResourceNames::forAd($customerId, $resourceAdgroupAdId), 'responsive_search_ad' => new ResponsiveSearchAdInfo([ 'headlines' => $headlines, 'descriptions' => $descriptions, ]), 'final_urls' => [$adLink], //'final_mobile_urls' => ['http://www.example.com/mobile'] ]);

$mutateAds = []; $adOperation = new AdOperation(); $adOperation->setUpdate($ad); $adOperation->setUpdateMask(FieldMasks::allSetFieldsOf($ad));

$mutateAds[ResourceNames::forAd($customerId, $resourceAdgroupAdId)] = $adOperation;

if (!empty($mutateAds)) { $adServiceClient = $googleAdsClient->getAdServiceClient(); $response = $adServiceClient->mutateAds($customerId, $mutateAds); foreach ($response->getResults() as $updatedAd) { //$updatedAd = $response1->getResults(); $testResource = $updatedAd->getResourceName(); echo "

1 UPDATED: $testResource

"; } }`

fiboknacky commented 12 months ago

Could you step back and follow these steps to run GetCampaigns first?

And do you use linux or what environment?

techshoppingiq commented 12 months ago

I have run this simplest example with following code https://github.com/googleads/google-ads-php/blob/main/examples/BasicOperations/GetCampaigns.php. I am using XAMPP in windows. And running code with core PHP. But still not getting log in file or screen with comment the line for logFilePath and uncomment.

techshoppingiq commented 12 months ago

Please help us to fix this, Evan i have run simplest code but not getting logs. That is become a major issue due to without log we can't explain real issue what we are facing.

fiboknacky commented 11 months ago

So, you see your campaigns printed on the command prompt, but no log even if you commented the file path out like you did in this comment?

I just tested on my machine and it shows both the result and the log, so I really have no idea either what happened there.

fiboknacky commented 11 months ago

Closing due to inactivity.