Hi Bryan.
Thanks a lot for the reply one again.
*1. REST transport: here is the code. *
public function profile()
{
// Either pass the required parameters for this example on the
command line, or insert them into the constants above.
$options = (new ArgumentParser())->parseCommandArguments([
ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT
]);
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId('XXXXXX......')
->withClientSecret('XXXXXX......')
->withRefreshToken('XXXXXX......')
->build();
// Construct a Google Ads client configured from a properties file
and the OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken('XXXXXX......')
->withLoginCustomerId('1234567890')
->build();
try {
self::runExample(
$googleAdsClient,
$options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID
);
} catch (GoogleAdsException $googleAdsException) {
echo '<pre>';
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure
details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach
($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
/** @var GoogleAdsError $error */
printf(
"\t%s: %s%s",
$error->getErrorCode()->getErrorCode(),
$error->getMessage(),
PHP_EOL
);
}
} catch (ApiException $apiException) {
echo '<pre>';
printf(
"ApiException was thrown with message '%s'.%s",
$apiException->getMessage(),
PHP_EOL
);
}
}
public static function runExample(GoogleAdsClient $googleAdsClient, int
$customerId)
{
$googleAdsServiceClient =
$googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves all campaigns.
$query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY
campaign.id';
// Issues a search stream request.
/** @var GoogleAdsServerStreamDecorator $stream */
$stream = $googleAdsServiceClient->searchStream($customerId,
$query);
// Iterates over all rows in all messages and prints the requested
field values for
// the campaign in each row.
foreach ($stream->readAll() as $response) {
/** @var SearchGoogleAdsStreamResponse $response */
foreach ($response->getResults() as $googleAdsRow) {
/** @var GoogleAdsRow $googleAdsRow */
printf(
"Campaign with ID %d and name '%s' was found.%s",
$googleAdsRow->getCampaign()->getId()->getValue(),
$googleAdsRow->getCampaign()->getName()->getValue(),
PHP_EOL
);
}
}
}
*2. Customer Id issue: *
I am using CUSTOMER_ID to retrieve the data from table campaign. Where do I
find the table lists and their corresponding use?
In the code above, there is a constant CUSTOMER_ID. I wish to make this
constant value dynamic after successful log in, means user will get the
customer id / ids to choose from once log in successfully.
*Common question:*
Is there anyway I can call Google Ads API using REST, such as,
$response =
file_get_contents("https://ads.google.com/api/v3/?param1=val1.........");
print_r($response);
Awaiting your reply.
Thanks,
Amit
On Thursday, March 26, 2020 at 1:14:25 AM UTC+5:30, adsapiforumadvisor
wrote:
>
> Hi Amit,
>
> I see you have two queries. You will find my answers below.
>
> 1. Issue with REST Transport.
> Could you provide the REST request and response logs where this error
> occurs so that I may further investigate this issue?
>
> 2. How to obtain Customer_ID dynamically.
> Could you clarify what you're using the customer_ID for? Are you trying to
> query for a list of customer_IDs? If so, you can use the Customer Report to
> pull customer.id
> <https://developers.google.com/google-ads/api/fields/v3/customer#customer.id>
> under
> the manager account.
>
> Let me know if you have further questions.
>
> Thank you,
> Bryan, Google Ads API Team
>
> ref:_00D1U1174p._5001UXVi3P:ref
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/981cd4d8-a550-491b-8f40-0e462eeb612e%40googlegroups.com.