I'm using the following Perl code to try to add a tag to an existing photo. 
The call fails with "Token invalid - AuthSub token has wrong scope"

#!/usr/public/bin/perl -w
 
use strict;
use JSON;
use JSON::WebToken;
use LWP::UserAgent;
use HTML::Entities;
use HTTP::Request::Common;
 
my $private_key_string = "-----BEGIN PRIVATE KEY-----xxxxxxxx-----END 
PRIVATE KEY-----\n";

my $time = time;
 
# https://developers.google.com/accounts/docs/OAuth2ServiceAccount
my $jwt = JSON::WebToken->encode({
                                  # your client email address here
                                  iss => 
'[email protected]',
                                  scope => 
'https://picasaweb.google.com/data/',
                                  aud => 
'https://www.googleapis.com/oauth2/v3/token',
                                  exp => $time + 3600,
                                  iat => $time,
                                 }, $private_key_string, 'RS256', {typ => 
'JWT'}
                                );
 
# Now post it to google
my $ua = LWP::UserAgent->new();
my $response = $ua->post('https://www.googleapis.com/oauth2/v3/token',
                         {grant_type => 
encode_entities('urn:ietf:params:oauth:grant-type:jwt-bearer'),
                          assertion => $jwt});
 
unless($response->is_success()) {
    die($response->code, "\n", $response->content, "\n");
}
 
my $data = decode_json($response->content);

# Update a photo with a tag
my $xml = <<EOT;
<entry xmlns='http://www.w3.org/2005/Atom'>
  <title>Test</title>
  <category scheme="http://schemas.google.com/g/2005#kind";
    term="http://schemas.google.com/photos/2007#tag"/>
</entry>
EOT

my $picasaweb_username = "xxxxxxxx";
my $album = "Test";
my $photo_id = "99999999";

my $url = 
"http://picasaweb.google.com/data/feed/api/user/$picasaweb_username/album/$album/photoid/$photo_id";;
my $req = HTTP::Request->new(POST => "$url");

   $req->content_type("application/atom+xml");
   $req->content($xml);
   $req->authorization('Bearer ' . $data->{access_token});
   $response = $ua->request($req)->as_string;

print $response;

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-picasa-data-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to