Loading ...
Sorry, an error occurred while loading the content.

SOAP::SOM return object

Expand Messages
  • discorogers
    Hi all, Would really appreciate your help. I m relatively new to Perl and SOAP, and I m trying to implement a connection to the Google Adwords API using
    Message 1 of 1 , Feb 15, 2009
    • 0 Attachment
      Hi all,

      Would really appreciate your help. I'm relatively new to Perl and
      SOAP, and I'm trying to implement a connection to the Google Adwords
      API using SOAP::Lite. I have it almost working but however I try and
      get a return value from SOAP::SOM (e.g. using valueof or result) I
      only seem to get the last element. Even calling valueof("//Body") just
      gives me one element. I have tried debugging the code and using
      Dumper, but the SOAP::Lite code is quite unreadable (at least to me :)
      and I can't work out whats going on.

      This what I get from valueof("//Body):

      $VAR1 = {
      'getKeywordVariationsResponse' => {

      'getKeywordVariationsReturn' => {

      'moreSpecific' => {

      'searchVolumeScale' => '2',

      'language' => '',

      'text' => 'trusted places 1',

      'advertiserCompetitionScale' => '3'

      }

      }
      }
      };

      But I know there is more than one KeywordVariation from using Dumper
      on the SOAP::SOM object.

      This is the code I am using:

      use strict;
      use warnings;
      use English '-no_match_vars';
      use SOAP::Lite;
      use Data::Dumper;
      binmode(STDOUT, ':utf8');

      # Provide AdWords login information.
      my $email = '';
      my $password = '';
      my $client_email = 'client_1+dan.j.rogers@...';
      my $useragent = 'QYPE: AdWords API Perl Sample Code';
      my $developer_token = 'dan.j.rogers@...++USD';
      my $application_token = 'INSERT_APPLICATION_TOKEN_HERE';

      # Set up service connection with autotyping disabled and fault handler
      # registered. To send requests to production environment, replace
      "sandbox" with
      # "adwords". To view XML request/response, uncomment
      # "SOAP::Lite->import(+trace => 'debug');".
      my $url =
      sprintf('https://%s.google.com/api/adwords/v12/KeywordToolService',
      'sandbox');

      my $wsdl = $url . '?wsdl';

      my $service =
      SOAP::Lite->service($wsdl)->autotype(0)->readable(1)->proxy($url);

      #my $service = SOAP::Lite->uri('urn:getKeywordVariations')->proxy($url);

      $service->on_fault(sub {
      my $response = $ARG[1];
      die('The following SOAP fault occurred:', "\n",
      ' faultcode: ', $response->faultcode(), "\n",
      ' faultstring: ', $response->faultstring(),
      "\n")
      });
      SOAP::Lite->import(+trace => 'debug');

      # Define SOAP headers.
      my @headers = (
      SOAP::Header->name('email' => $email),
      SOAP::Header->name('password' => $password),
      SOAP::Header->name('clientEmail' => $client_email),
      SOAP::Header->name('useragent' => $useragent),
      SOAP::Header->name('developerToken' => $developer_token),
      SOAP::Header->name('applicationToken' => $application_token)
      );

      # Create seed keyword structure.
      my $seed_keyword = {
      'negative' => 'false',
      'text' => 'trusted places',
      'type' => 'Broad',
      };

      my $seed_keywords = SOAP::Data->name('seed_keywords' => [$seed_keyword]);
      my $use_synonyms = SOAP::Data->name('useSynonyms' => 'true');
      my $languages = SOAP::Data->name('languages' => ['en']);
      my $countries = SOAP::Data->name('countries' => ['US']);

      # Get keyword variations.
      my $variation_lists = $service->call('getKeywordVariations' =>
      $seed_keywords,
      $use_synonyms, $languages, $countries, @headers);

      print Dumper($variation_lists);

      my @data = $variation_lists->valueof("//Body");

      foreach my $data_word (@data){
      print Dumper($data_word);
      }


      If anyone knows where I am going wrong I'd be most grateful!

      Thanks for your help.

      Danielle
    Your message has been successfully submitted and would be delivered to recipients shortly.