I have been searching for answers and testing my code for days, but
still don't have it working. This article is a great start for
information about using the v200909 Google AdWords API without the
Client Library, but it's hard to translate the sample code to other
API functions:

http://code.google.com/p/google-api-adwords-php/wiki/NoClientLibrary

I'm working with our analytics team to extract some keyword data
(alternate keyword variations and monthly search estimates) and would
rather not install the whole library. Seems like a lot of extra code
and files for such limited use of the API. Please let me know if this
thought is incorrect.

Here is my PHP code making the request (the SOAP error output is
below):

<?php
error_reporting(E_STRICT | E_ALL);
require_once('AuthToken.php');

class Paging {
        function Paging($startIndex = 0, $numberResults = 10) {
                $this->startIndex = $startIndex;
                $this->numberResults = $numberResults;
        }
}

class TargetingIdeaSelector {
   function TargetingIdeaSelector($searchParameters) {
       $this->searchParameters = array($searchParameters);
       $this->ideaType = "KEYWORD";
       $this->requestType = "IDEAS";
       $this->paging = new Paging();
   }
}

class RelatedToKeywordSearchParameter {
        function RelatedToKeywordSearchParameter($keywords) {
                $this->keywords = $keywords;
        }
}

class Keyword {
        function Keyword($text, $matchType) {
                $this->text = $text;
                $this->matchType = $matchType;
        }
}

// Provide AdWords login information.
$email = 'INSERT_LOGIN_EMAIL_HERE';
$password = 'INSERT_PASSWORD_HERE';
$client_email = 'INSERT_CLIENT_LOGIN_EMAIL_HERE';
$userAgent = 'INSERT_COMPANY_NAME: AdWords API PHP Code Example';
$developerToken = 'INSERT_DEVELOPER_TOKEN_HERE';
$applicationToken = 'INSERT_APPLICATION_TOKEN_HERE';

// Create authToken
$authToken = new AuthToken($email, $password, 'adwords', 'PHP Sample
Code', 'GOOGLE');

// Set SOAP and XML settings. To send requests to production
environment
$wsdl = 'https://adwords.google.com/api/adwords/o/v200909/
TargetingIdeaService?wsdl';
$namespace = 'https://adwords.google.com/api/adwords/o/v200909';
$options = array(
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
    'encoding' => 'utf-8');

// Get the TargetingIdeaService
$targetingIdeaService = new SoapClient($wsdl, $options);

// Set headers
$headers = new SoapHeader($namespace, 'RequestHeader', array(
    'authToken' => $authToken->GetAuthToken(),
    'clientEmail' => $client_email,
    'userAgent' => $userAgent,
    'developerToken' => $developerToken,
    'applicationToken' => $applicationToken));
$targetingIdeaService->__setSoapHeaders($headers);

try {
        // Get related keywords
        $keywords = array(new Keyword("mars cruise", "BROAD"));
        $selector = new TargetingIdeaSelector(new
RelatedToKeywordSearchParameter($keywords));
        $response = $targetingIdeaService->get(array("selector" =>
$selector));

        // for Output Testing
        //print_r($selector);
        //exit;

  // Display related keywords.
  if (isset($response->entries)) {
    foreach ($response->entries as $targetingIdea) {
      $keyword = $targetingIdea->data[0]->value->value;
      print 'Keyword with text "' . $keyword->text . '" and match type
"'
          . $keyword->matchType . "\" was found.\n";
    }
  } else {
    print "No related keywords were found.\n";
  }
} catch (Exception $e) {
  print_r($e);
}
?>

SoapFault exception:

SoapFault exception: [soap:Server] Unmarshalling Error: Unable to
create an instance of
com.google.ads.api.services.targetingideas.v200909.jaxbgen.SearchParameter
in /var/www/vhosts/nonbot.com/httpdocs/tools/_dev/google-api_kwd.php:
68

Stack trace:
#0 [internal function]: SoapClient->__call('get', Array)
#1 /var/www/vhosts/nonbot.com/httpdocs/tools/_dev/google-
api_kwd.php(68): SoapClient->get(Array)
#2 {main}

THANK YOU!

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Have you migrated to v200909 yet?
The v13 sunset is on April 22, 2010.

Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords 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

Reply via email to