Hi,
I'm trying to write a script, that will log into AdSense, with your details - and grab the code to show on your site.
The code I have it (NB - this is for Gossamer Links, as a plugin - but I'm hoping to get some feedback here
)
Now, this is called fine - and I see what I would expect on the debug info:
..but I get this error:
Do you have to get something special done, for this to work? This code is taken from - http://code.google.com/apis/adsense/developer/samples/perl/GenerateAdCodeSnippet.pl.txt (I had to edit it a bit, to add in "my" statements, so it would work with strict)
Any suggestions are much welcomed.
TIA
Andy
I'm trying to write a script, that will log into AdSense, with your details - and grab the code to show on your site.
The code I have it (NB - this is for Gossamer Links, as a plugin - but I'm hoping to get some feedback here
Code:
# ==================================================================
# Plugins::GetAdsenseCodeAPI - Auto Generated Program Module
#
# Plugins::GetAdsenseCodeAPI
# Author : Andy Newby
# Version : 1
# Updated : Tue Apr 8 04:03:36 2008
#
# ==================================================================
#
package Plugins::GetAdsenseCodeAPI;
# ==================================================================
use strict;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/:objects/;
# Inherit from base class for debug and error methods
@Plugins::GetAdsenseCodeAPI::ISA = qw(GT::Base);
# Your code begins here.
# PLUGIN HOOKS
# ===================================================================
sub do_signup {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'use_signup' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'use_signup' code to run, otherwise the code will continue as normal.
#
my (@args) = @_;
# google_email google_pwd google_pub_id
print $IN->header;
print "HERE";
if ($IN->param('google_email') && $IN->param('google_pwd') && $IN->param('google_pub_id')) {
get_google_code($IN->param('google_email'),$IN->param('google_pwd'),$IN->param('google_pub_id'));
}
return @args;
}
sub get_google_code {
use SOAP::Lite;
# SOAP Headers
my $developerEmail = $_[0]; # 'REPLACE WITH DEVELOPER\'S EMAIL';
my $developerPassword = $_[1]; #'REPLACE WITH DEVELOPER\'S PASSWORD';
my $clientId = $_[2]; #'REPLACE WITH CLIENT\'S ID';
print qq~
Email: $developerEmail<br />
Pass: $developerPassword <br />
ClientID: $clientId
~;
# The namespace used for API headers.
my $namespace = "[URL unfurl="true"]http://www.google.com/api/adsense/v2";[/URL]
# Set up the Account service connection
my $accountWsdlUrl = "[URL unfurl="true"]http://www.google.com/api/adsense/v2/AccountService?WSDL";[/URL]
my $accountService = SOAP::Lite->service($accountWsdlUrl);
# Set up the AdSenseForContent connection
my $adSenseForContentWsdlUrl =
"[URL unfurl="true"]http://www.google.com/api/adsense/v2/AdSenseForContentService?WSDL";[/URL]
my $adSenseForContentService = SOAP::Lite->service($adSenseForContentWsdlUrl);
# Uncomment this line to display the XML request/response.
#$accountService->on_debug( sub { print @_ } );
#$adSenseForContentService->on_debug( sub { print @_ });
# Disable autotyping.
$accountService->autotype(0);
$adSenseForContentService->autotype(0);
# Register a fault handler.
$accountService->on_fault(\&faulthandler);
$adSenseForContentService->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($clientId)->uri($namespace)->prefix("impl"));
# Get the user's AdSense for Content syndication service ID
my $synServiceType = "ContentAds";
my $synServiceData = $accountService->getSyndicationService($synServiceType, @headers);
my $synServiceId = $synServiceData->{"id"};
# we need to create a style for the code we will generate; we could
# use a style we previously saved with saveAdStyle, but here we assume
# we don't have any such styles
my $adStyle = {
"name" => "demoStyle",
"borderColor" => "#0000FF",
"backgroundColor" => "#FFFFFF",
"titleColor" => "#FF0000",
"textColor" => "#00FF00",
"urlColor" => "#FFFF00",
};
# create the other parameters to generateAdCode
my $adUnitType = "TextOnly";
my $layout = "728x90";
my $alternate = "#FFFFFF";
my $isFramedPage = "false";
my $channelName = undef;
my $codeSnippet = $adSenseForContentService->generateAdCode($synServiceId,
$adStyle, $adUnitType, $layout, $alternate, $isFramedPage, $channelName,
@headers);
print $IN->header;
print "GOOGEL CODE:" . $codeSnippet;
#return $codeSnippet;
}
### 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);
}
# Always end with a 1.
1;
Now, this is called fine - and I see what I would expect on the debug info:
HERE Email: andy.newby@gmail.com
Pass: (my password - removed)
ClientID: pub-3171934375285541
..but I get this error:
Code:
A fatal error has occured:
SOAP Fault: Error Code 114. The 'developer_email' header does not represent an authorized developer. at /home/[URL unfurl="true"]wwwjoin/public_html/cgi-bin/directory/admin/Plugins/GetAdsenseCodeAPI.pm[/URL] line 143.
Please enable debugging in setup for more details.
Do you have to get something special done, for this to work? This code is taken from - http://code.google.com/apis/adsense/developer/samples/perl/GenerateAdCodeSnippet.pl.txt (I had to edit it a bit, to add in "my" statements, so it would work with strict)
Any suggestions are much welcomed.
TIA
Andy