Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax error, unexpected '|', expecting ';' or '{' in <b>/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V14/ServiceClientFactoryTrait.php #933

Closed
jitendra-cedcoss opened this issue Aug 11, 2023 · 1 comment
Labels
bug Something isn't working triage Need triage

Comments

@jitendra-cedcoss
Copy link

google-ads-php with version v20.1.0:

  • Google Ads API version: V14

Your environment: PHP 7.4

I was checking Upload offline conversion, but I am unable to run this API request due to the below error.
** syntax error, unexpected '|', expecting ';' or '{' in /vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V14/ServiceClientFactoryTrait.php **

I am sharing an example url which I was trying for the offline conversion.
Here is the link:

public static function runExample(
GoogleAdsClient $googleAdsClient,
int $customerId,
int $conversionActionId,
?string $gclid,
?string $gbraid,
?string $wbraid,
string $conversionDateTime,
float $conversionValue,
?string $conversionCustomVariableId,
?string $conversionCustomVariableValue
) {
// Verifies that exactly one of gclid, gbraid, and wbraid is specified, as required.
// See https://developers.google.com/google-ads/api/docs/conversions/upload-clicks for details.
$nonNullFields = array_filter(
[$gclid, $gbraid, $wbraid],
function ($field) {
return !is_null($field);
}
);
if (count($nonNullFields) !== 1) {
throw new \UnexpectedValueException(
sprintf(
"Exactly 1 of gclid, gbraid or wbraid is required, but %d ID values were "
. "provided",
count($nonNullFields)
)
);
}
// Creates a click conversion by specifying currency as USD.
$clickConversion = new ClickConversion([
'conversion_action' =>
ResourceNames::forConversionAction($customerId, $conversionActionId),
'conversion_value' => $conversionValue,
'conversion_date_time' => $conversionDateTime,
'currency_code' => 'USD'
]);
// Sets the single specified ID field.
if (!is_null($gclid)) {
$clickConversion->setGclid($gclid);
} elseif (!is_null($gbraid)) {
$clickConversion->setGbraid($gbraid);
} else {
$clickConversion->setWbraid($wbraid);
}
if (!is_null($conversionCustomVariableId) && !is_null($conversionCustomVariableValue)) {
$clickConversion->setCustomVariables([new CustomVariable([
'conversion_custom_variable' => ResourceNames::forConversionCustomVariable(
$customerId,
$conversionCustomVariableId
),
'value' => $conversionCustomVariableValue
])]);
}
// Issues a request to upload the click conversion.
$conversionUploadServiceClient = $googleAdsClient->getConversionUploadServiceClient();
/** @var UploadClickConversionsResponse $response */
$response = $conversionUploadServiceClient->uploadClickConversions(
UploadClickConversionsRequest::build($customerId, [$clickConversion], true)
);
// Prints the status message if any partial failure error is returned.
// Note: The details of each partial failure error are not printed here, you can refer to
// the example HandlePartialFailure.php to learn more.
if ($response->hasPartialFailureError()) {
printf(
"Partial failures occurred: '%s'.%s",
$response->getPartialFailureError()->getMessage(),
PHP_EOL
);
} else {
// Prints the result if exists.
/** @var ClickConversionResult $uploadedClickConversion */
$uploadedClickConversion = $response->getResults()[0];
printf(
"Uploaded click conversion that occurred at '%s' from Google Click ID '%s' " .
"to '%s'.%s",
$uploadedClickConversion->getConversionDateTime(),
$uploadedClickConversion->getGclid(),
$uploadedClickConversion->getConversionAction(),
PHP_EOL
);
}
}

https://developers.google.com/google-ads/api/docs/conversions/upload-clicks

**Steps to reproduce: Just use above example in your php file and try to record upload Offline conversion **

Expected behavior: API should run successfully and conversion should record.

** Actual Result: Got below error
syntax error, unexpected '|', expecting ';' or '{' in /vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V14/ServiceClientFactoryTrait.php **

@jitendra-cedcoss jitendra-cedcoss added bug Something isn't working triage Need triage labels Aug 11, 2023
@fiboknacky
Copy link
Member

We now require PHP 8.0 as a minimum PHP version for this library.
Please see this issue for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Need triage
Projects
None yet
Development

No branches or pull requests

2 participants