googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
656 stars 769 forks source link

Ad Manager, Call to undefined method Google\AdsApi\AdManager\AdManagerSession::getDeveloperToken() #703

Closed gabyyro closed 3 years ago

gabyyro commented 3 years ago

I am trying to use the TargetingIdea Service https://developers.google.com/adwords/api/docs/guides/targeting-idea-service#use_case

I setup the Service account flow with Google Ad manager. Network connection is succesful. However I cannot use the TargetingIdeaService. Following code returns:

PHP Fatal error: Uncaught Error: Call to undefined method Google\AdsApi\AdManager\AdManagerSession::getDeveloperToken() in /home/zelistdezvoltare/public_html/crons_v2/google_search/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/AdWordsHeaderHandler.php:88

I understood I do need a developer token only if I follow the installed application flow, not service one. Also, isn't the developer token used only for installed and web apps?

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

use Google\AdsApi\Common\OAuth2TokenBuilder; use Google\AdsApi\AdManager\AdManagerSessionBuilder; use Google\AdsApi\AdManager\v202011\ServiceFactory;

use Google\AdsApi\AdWords\AdWordsServices; use Google\AdsApi\AdWords\AdWordsSessionBuilder; use Google\AdsApi\AdWords\AdWordsSession; use Google\AdsApi\AdWords\v201809\cm\Paging; use Google\AdsApi\AdWords\v201809\o\TargetingIdeaSelector; use Google\AdsApi\AdWords\v201809\o\TargetingIdeaService; use Google\AdsApi\AdWords\v201809\o\RequestType; use Google\AdsApi\AdWords\v201809\o\IdeaType; use Google\AdsApi\AdWords\v201809\o\AttributeType; use Google\AdsApi\AdWords\v201809\o\RelatedToQuerySearchParameter;

$oAuth2Credential = (new OAuth2TokenBuilder()) ->fromFile() ->build();

$session = (new AdManagerSessionBuilder()) ->fromFile() ->withOAuth2Credential($oAuth2Credential) ->build();

$serviceFactory = new ServiceFactory();

$networkService = $serviceFactory->createNetworkService($session);

//Test network connection, all fine $network = $networkService->getCurrentNetwork();

$selector = new TargetingIdeaSelector(); $selector->setRequestType(RequestType::IDEAS); $selector->setIdeaType(IdeaType::KEYWORD);

$selector->setRequestedAttributeTypes( [ AttributeType::KEYWORD_TEXT, AttributeType::SEARCH_VOLUME, AttributeType::AVERAGE_CPC, AttributeType::COMPETITION, AttributeType::CATEGORY_PRODUCTS_AND_SERVICES ] );

$paging = new Paging(); $paging->setStartIndex(0); $paging->setNumberResults(10); $selector->setPaging($paging);

$searchParameters = []; // Create related to query search parameter. $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); $relatedToQuerySearchParameter->setQueries( [ 'bakery', 'pastries', 'birthday cake' ] ); $searchParameters[] = $relatedToQuerySearchParameter;

// Get keyword ideas. $adWordsServices = new AdWordsServices; $targetingIdeaService = $adWordsServices->get($session, TargetingIdeaService::class);

$page = $targetingIdeaService->get($selector);

var_export($page); exit;`

My adsapni_php.ini file looks like this:

`[AD_MANAGER] ; Required Ad Manager API properties. Details can be found at: ; https://developers.google.com/ad-manager/docs/soap_xml networkCode = "xxxxxxxxxxx" applicationName = "my_app_name"

; Optional additional Ad Manager API settings. ; endpoint = "https://ads.google.com/"

[OAUTH2] ; Required OAuth2 credentials. Uncomment and fill in the values for the ; appropriate flow based on your use case. See the README for guidance: ; https://github.com/googleads/googleads-php-lib/blob/master/README.md#getting-started

; For service account flow. jsonKeyFilePath = "myapp-1ad6629a9946.json" scopes = "https://www.googleapis.com/auth/dfp" impersonatedEmail = "searchvolume@myaccount.iam.gserviceaccount.com"

; For installed application or web application flow. ; clientId = "INSERT_OAUTH2_CLIENT_ID_HERE" ; clientSecret = "INSERT_OAUTH2_CLIENT_SECRET_HERE" ; refreshToken = "INSERT_OAUTH2_REFRESH_TOKEN_HERE"

[SOAP] ; Optional SOAP settings. See SoapSettingsBuilder.php for more information. ; compressionLevel =

[CONNECTION] ; Optional proxy settings to be used by requests. ; If you don't have username and password, just specify host and port. ; proxy = "protocol://user:pass@host:port"

[LOGGING] ; Optional logging settings. ; soapLogFilePath = "path/to/your/soap.log" ; soapLogLevel = "INFO"; ; reportDownloaderLogFilePath = "path/to/your/report-downloader.log" ; reportDownloaderLogLevel = "INFO"`

fiboknacky commented 3 years ago

Are you trying to use Ad Manager API or AdWords API? They're different products, so you cannot mix them together. If the latter, we recommend you use the Google Ads API via this repository instead.

gabyyro commented 3 years ago

I was trying to use the TargetingIdea Service which I saw is called with AdWords API. Hoewever, when I looked at documentation, it seems that AdWords API was meant more for application flow, I need it to extract reports from console commands, no web or mobile interface. What is recommended approach, I have to switch to other implementation, cannot work with Ad Manager and service account? I need Adwords API with user token?

fiboknacky commented 3 years ago

As your questions are related to the products in general, could you please reach out to the experts on this forum? Feel free to get back to this if you still have a library-related issue. Thank you.

gabyyro commented 3 years ago

Ok, will try, thanks!