0

I'm trying to use AdWords API from Google in a cakePHP application. I need to search for keywords at some point inside an already existing model that I made.

The idea is to get information about the keyword if I dont' already got it in my database. But when I need to use some classes of adWords, I'm getting this error :

Error: Class 'TargetingIdeaSelector' not found
File: C:\wamp64\www\projet\app\Model\Keyword.php

Line: 36

Here is an idea of the code I have :

public function getsuggestions($word, $someData) {

        if(!empty($word) && $word != '') {
            $data = $this->find('all', array(
                'conditions' => array('Keyword.mot_saisi' => $word)
            ));
            if(!empty($data)) { 
                $motcles = split(",",$data['0']['Keyword']['result'],11);
                $motcles['10'] = $word;

                return $motcles;
            }
            else {
                // Create selector.
                $selector = new TargetingIdeaSelector(); //Here is the error
                $selector->requestType = 'IDEAS';
                $selector->ideaType = 'KEYWORD';
                $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 
'SEARCH_VOLUME',
                    'CATEGORY_PRODUCTS_AND_SERVICES');
                // Create language search parameter (optional).
                // The ID can be found in the documentation:
                //   
https://developers.google.com/adwords/api/docs/appendix/languagecodes
                // Note: As of v201302, only a single language parameter is 
allowed.
                $languageParameter = new LanguageSearchParameter();
                $french = new Language();
                $french->id = 1002;
                $languageParameter->languages = array($french);
                // Create related to query search parameter.
                $relatedToQuerySearchParameter = new 
RelatedToQuerySearchParameter();
                $relatedToQuerySearchParameter->setQueries(array($word));
                $selector->searchParameters[] = 
$relatedToQuerySearchParameter;
                $selector->searchParameters[] = $languageParameter;
                // Set selector paging (required by this service).
                $paging = new Paging();
                $paging->setStartIndex(0);
                $paging->setNumberResults(10);
                $selector->setPaging($paging);

                // Make the get request.
                $content = $targetingIdeaService->get($selector);

[...]

I guess adWords classes are not included in my model, but how can I include all the adWords content so that I can use multiple classes inside my model ?

(I have googleads-php-lib directly inside my project)

EDIT

Here is the exact solution :

require_once __DIR__ . '../../Vendor/autoload.php';
use Google\AdsApi\AdWords\v201710\o\TargetingIdeaSelector;
use Google\AdsApi\AdWords\v201710\o\LanguageSearchParameter;
use Google\AdsApi\AdWords\v201710\o\RelatedToQuerySearchParameter;
use Google\AdsApi\AdWords\v201710\cm\Language;
use Google\AdsApi\AdWords\v201710\cm\Paging;
Community
  • 1
  • 1
SnowYou
  • 39
  • 6

1 Answers1

1

(I have googleads-php-lib directly inside my project)

You need to tell the auto loader where to find it and use the use statement inside your file.

floriank
  • 25,546
  • 9
  • 42
  • 66
  • Hi, thank you for your answer. I worked on it again but I can't quite get how I should write it. I added : require __DIR__ . '/../vendor/autoload.php'; use googleads_php_lib_14_0_0\src\Google\Api\Ads\AdWords\v201605\TargetingIdeaService Because I need the function TargetingIdeaSelector which is inside the TargetingIdeaService php file. But it seems like it doesn't work, The TargetingIdeaSelector class is still unknown to my class. I raid the links you shared, but still can't figure it out. Am I missing a step ? – SnowYou Jun 01 '18 at 08:42