Hi,
I'm trying to write a plugin, that will log into AdSense, with your details - and grab the code to show on your site. This is aimed to work with my AdSenseShare plugin - which doesn't seem to work fully when you use the new AdSense code they are giving you (with AdSenseChannel) .
The code I have it:
# 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 = "http://www.google.com/api/adsense/v2";
# Set up the Account service connection
my $accountWsdlUrl = "http://www.google.com/api/adsense/v2/AccountService?WSDL";
my $accountService = SOAP::Lite->service($accountWsdlUrl);
# Set up the AdSenseForContent connection
my $adSenseForContentWsdlUrl =
"http://www.google.com/api/adsense/v2/AdSenseForContentService?WSDL";
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:
Pass: (my password - removed)
ClientID: pub-3171934375285541
..but I get this error:
SOAP Fault: Error Code 114. The 'developer_email' header does not represent an authorized developer. at /home/wwwjoin/public_html/cgi-bin/directory/admin/Plugins/GetAdsenseCodeAPI.pm 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/...AdCodeSnippet.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 (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
I'm trying to write a plugin, that will log into AdSense, with your details - and grab the code to show on your site. This is aimed to work with my AdSenseShare plugin - which doesn't seem to work fully when you use the new AdSense code they are giving you (with AdSenseChannel) .
The code I have it:
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 = "http://www.google.com/api/adsense/v2";
# Set up the Account service connection
my $accountWsdlUrl = "http://www.google.com/api/adsense/v2/AccountService?WSDL";
my $accountService = SOAP::Lite->service($accountWsdlUrl);
# Set up the AdSenseForContent connection
my $adSenseForContentWsdlUrl =
"http://www.google.com/api/adsense/v2/AdSenseForContentService?WSDL";
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:
Quote:
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/wwwjoin/public_html/cgi-bin/directory/admin/Plugins/GetAdsenseCodeAPI.pm 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/...AdCodeSnippet.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 (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!