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
291 stars 260 forks source link

searchStream() is not working #304

Closed amitklahiri closed 4 years ago

amitklahiri commented 4 years ago

Hi.

I am using the latest version of the client library as available using composer install option. I am getting the below error .

I am using it with PHP Laravel framework.

Here is my code,

 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
                );
            }
        }
    }

It looks like getting the error, in this line, $stream = $googleAdsServiceClient->searchStream($customerId, $query);

And it occurs because the function searchStream(.....), which seems unavailable.

What am I supposed to do now? Looking forward to solution ASAP.

Thanks.

PierrickVoulet commented 4 years ago

Hi @amitklahiri - could you provide more information for us to investigate, e.g.:

There are two different methods to search and streaming is the one used in this particular code example. Could you give a try with paging instead? You can refer to the code example GetAdGroups.php.

fiboknacky commented 4 years ago

And, just in case, as you've not included the import statements, please make sure that this line fetches V3 GoogleAdsClient:

$googleAdsClient->getGoogleAdsServiceClient()
sreenumalae commented 4 years ago

In GetCampaigns.php line number 102 and 103 ==> $stream =$googleAdsServiceClient->searchStream($customerId, $query);

Do we have any option like search instead of searchStream

I have issues in my server i cant add dynamic library

So, can you please let me know if there is another way without using searchStream.

fiboknacky commented 4 years ago

searchStream is a new feature, but you can still use search if you wish.

sreenumalae commented 4 years ago

Hey @fiboknacky, thanks for the reply. Do we need grpc for search?

fiboknacky commented 4 years ago

gRPC is recommended as always, but you probably can use REST as well. However, logging is not well supported for REST.

As it seems your issue wouldn't exactly be the same as this issue, could you create a new issue if you have further detail you wish to know more?

amitklahiri commented 4 years ago

I am using this library with Laravel 6 PHP framework.

  1. I have installed all the require packages as available in this packagist URL. https://packagist.org/packages/googleads/google-ads-php

  2. But I do not integrate the gRPC to the Laravel separately anywhere. Am I need to do further configuration?

  3. Is this library works with the Laravel framework?

PierrickVoulet commented 4 years ago

I am closing this issue because this seems to be a duplicate of #311 . Feel free to reopen if it is not the case.