Closed techshoppingiq closed 11 months ago
Could you please share the log of the request you sent to the API server?
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();
Can you use google_ads_php.ini
? That should be faster since you can just specify the path to the log file.
We are using this above code for multiple client ids dynamically, Can you guide use how we can use google_ads_php.ini,
Please take a look at this guide. Let me know if you have questions.
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.
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
.
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.
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.
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.
Did you try what I suggested--using file.log
? What happened?
Yes i tried it but till not get logs.
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.
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);
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
?
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
"; }If you comment out the logFilePath
, do you get a log printed out on your screen?
Tried but not printed on screen.
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.
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.
`<?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
"; } }`Could you step back and follow these steps to run GetCampaigns first?
And do you use linux or what environment?
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.
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.
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.
Closing due to inactivity.
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