Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AdSense API - developer_email not valid? :/

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
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 :))
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
 
looks like you have to signup with google as an authorized developer?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi,

Yeah, thats what I thought - but the weird thing is - those details I'm giving *should* be for the person who's trying to setup their adsense code on our site.

A little background as to why I'm trying to do this:

Basically, we offer a "share" of adsense space on our forum, for people who have an adsense ID. Anyone who has more than xx posts, gets a 50/50 share of adspace on their threads.

The problem is, its not as simple as just getting the code (via me logging in), and replacing the pub-id, cos that gives a weird error in IE (a missing file error - probably cos the other paramaters are not setup right).

Any more ideas are much appreciated :/

Cheers

Andy
 
Mmm... not getting much help from the AdSense API Support usergroup either :/
 
The problem is, its not as simple as just getting the code (via me logging in), and replacing the pub-id, cos that gives a weird error in IE
Well, it should be that simple if you're doing it properly.

Your forum (perl) software generates some HTML and Javascript that's sent to the browser. Part of the adsense javascript is a line like this:
Code:
google_ad_client = "pub-5025107523962683";
Provided you can get the right number into that field, you're home free. My guess is that your "weird error" code is missing out one of the quotes, causing a knock-on error somewhere else.

Be that as it may - View Source is your friend. Use it to see what code your forum software is spiiting out, see how it differs from what Google want, and fix it.

And/or post a URL here so we can take a look.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hi,

Mmm.. well, heres an example:


If you refresh the page, it works 1 time - then not the next (its a 50/50 share, so every time someone refreshes the page, it rotates between the site owners pub-id, and mine (still developing the site =))

It *only* seems to do this in IE, which is really odd :/

Also - see attachment (this is what I see in IE 7)

TIA for any help

Andy
 
Ah, found something interesting (in case anyone else comes to this problem :)


Seems you have to apply as a developer, to use the API (with they'd told me about this earlier on their API page - had to dig quite deep to find this).

Anyway, heres to hoping it'll work then =)

Cheers

Andy
 
Hi,

Getting a little closer.

For some reason - I'm still getting this error:

SOAP Fault: Error Code 101. The request did not contain a header named 'developer_email'. at test2.cgi line 133.


However, the SOAP code being returned is:


<SOAP-ENV:Header>
<impl:developer_email xmlns:impl=" <impl:developer_password xmlns:impl=" <impl:client_id xmlns:impl="</SOAP-ENV:Header>

... why would it still be saying the headers don't have the develoer_email in though? :/

TIA

Andy
 
Is your email address you registered with really
adsensedeveloper1@google.com

because I have a hard time believeing you work for google.com :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hi,

Nope - I don't work for google <G>

This is what I got in my email (welcome one);

To access the sandbox, pass the following credentials in your request header:

developer_email: adsensedeveloper1@google.com
developer_password: password here

This is only for accessing sandbox.google.com, not the live API.

However, I'm using the Sandbox - and even then, it still refuses to work *mad*

Thanks for the reply though =)

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top