#!/usr/bin/perl -w # # Copyright 2005 Google Inc. All rights reserved. use SOAP::Lite; # Demo of using Account service with SOAP::Lite to create # an account # SOAP Headers $developerEmail = 'REPLACE WITH DEVELOPER\'S EMAIL'; $developerPassword = 'REPLACE WITH DEVELOPER\'S PASSWORD'; # The namespace used for API headers. my $namespace = "http://www.google.com/api/adsense/v2"; # Set up the connection to the server. $wsdl_url = "http://www.google.com/api/adsense/v2/AccountService?WSDL"; my $accountService = SOAP::Lite->service($wsdl_url); # Uncomment this line to display the XML request/response. #$accountService->on_debug( sub { print @_ } ); # Disable autotyping. $accountService->autotype(0); # Register a fault handler. $accountService->on_fault(\&faulthandler); my @headers = (SOAP::Header->name("developer_email")->value($developerEmail)->uri($namespace)->prefix("impl"), SOAP::Header->name("developer_password")->value($developerPassword)->uri($namespace)->prefix("impl"), SOAP::Header->name("client_id")->value("ignored")->uri($namespace)->prefix("impl")); # Create the parameters. $loginEmail = 'users_address_here@example.com'; $entityType = 'Individual'; $websiteUrl = 'http://test.example.com'; $websiteLocale = 'en'; $usersPreferredLocale = 'en_US'; $emailPromotionPreferences = "true"; $synServiceTypes = ["ContentAds"]; $hasAcceptedTCs = "true"; # Call the web service method. my $synServiceData = $accountService->createAdSenseAccount($loginEmail, $entityType, $websiteUrl, $websiteLocale, $usersPreferredLocale, $emailPromotionPreferences, $synServiceTypes, $hasAcceptedTCs, @headers); # Extract and print results. if (ref($synServiceData) eq "ARRAY") { $synServiceId = ($synServiceData)->[0]->{"id"}; $synServiceType = ($synServiceData)->[0]->{"type"}; } else { $synServiceId = ($synServiceData)->{"id"}; $synServiceType = ($synServiceData)->{"type"}; } print "Just created an AdSense account. This new account has an associated " . $synServiceType . " syndication service with id " . $synServiceId . "\n"; ### Helper functions sub faulthandler { my ($soap, $res) = @_; my $errorMessage = "SOAP Fault: " . "Error Code " . $res->faultdetail->{"code"} . ". " . $res->faultdetail->{"message"}; if (defined $res->faultdetail->{"trigger"}) { $errorMessage .= " \"" . $res->faultdetail->{"trigger"} . "\" "; } if (defined $res->faultdetail->{"triggerDetails"}) { $errorMessage .= $res->faultdetail->{"triggerDetails"}; } die($errorMessage); }