Google-ContentAPI
view release on metacpan or search on metacpan
Revision history for Google::ContentAPI.
1.03 2020-12-10 Added support for Google Content API for Shopping v2.1 via new
'endpoint' attribute. If endpoint attribute not provided, defaults
to v2.0 endpoint for backwards compatibility. Google::ContentAPI
is code compatible with both v2.0 and v2.1 endpoints.
You may need to update your application to account for several
breaking changes introduced in v2.1. Review to Google's migration document,
"Migrating from Content API v2 to v2.1" at
https://developers.google.com/shopping-content/guides/migration
1.02 2018-04-11 Added accountstatuses and productstatuses methods. Also added
a "custom" resource to perform methods that are not implemented
by this module.
Authentication is done via Service Account credentials. See the following for details:
L<https://developers.google.com/shopping-content/v2/how-tos/service-accounts>
You will also need to create a Merchant Center Account:
L<https://developers.google.com/shopping-content/v2/quickstart>
For convenience, add your Merchant account ID to the *.json file provided by Google.
Your complete *.json file, after adding your merchant ID, will look something like this:
{
"endpoint": "https://www.googleapis.com/content/v2.1",
"merchant_id": "123456789",
"type": "service_account",
"project_id": "content-api-194321",
"private_key_id": "11b8e20c2540c788e98b49e623ae8167dc3e4a6f",
"private_key": "-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----\n",
"client_email": "google@content-api.iam.gserviceaccount.com",
"client_id": "999999999",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google%40content-api.iam.gserviceaccount.com"
}
=head1 SYNOPSIS
use Google::ContentAPI;
use Data::Dumper;
my $google = Google::ContentAPI->new({
endpoint => 'https://www.googleapis.com/content/v2.1',
debug => 0,
config_file => 'content-api-key.json',
config_json => $json_text,
merchant_id => '123456789',
});
my ($result, $products, $batch_id, $product_id);
# get account auth info (merchantId)
$result = $google->get(
);
print "$result->{code} ". ($result->{code} eq '200' ? 'success' : 'failure') ."\n";
print "Product status: \n". Dumper $result;
=head1 METHODS AND FUNCTIONS
=head2 new()
Create a new Google::ContentAPI object
=head3 endpoint
API endpoint to use.
v2.1 endpoint is 'https://www.googleapis.com/content/v2.1'.
v2.0 endpoint is 'https://www.googleapis.com/content/v2'.
If not provided, default to v2.0 endpoint for backwards compatibility.
=head3 debug
Displays API debug information
=head3 config_file
Path and filename of external C<.json> config file.
Either config_file or config_json must be provided. If both config_file
and config_json are provided, config_file will be used.
lib/Google/ContentAPI.pm view on Meta::CPAN
#
# Authentication is done via Service Account credentials. For details see:
# https://developers.google.com/shopping-content/v2/how-tos/service-accounts
#
# AUTHOR
#
# Bill Gerrard <bill@gerrard.org>
#
# VERSION HISTORY
#
# + v1.03 12/10/2020 Allow custom endpoint, update docs for v2.1 API
# + v1.02 04/11/2018 Add accountstatuses, productstatuses methods. Add "custom" resource
# + v1.01 03/27/2018 Added config_json, merchant_id options and switched to Crypt::JWT
# + v1.00 03/23/2018 initial release
#
# COPYRIGHT AND LICENSE
#
# Copyright (C) 2018,2020 Bill Gerrard
#
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself, either Perl version 5.20.2 or,
lib/Google/ContentAPI.pm view on Meta::CPAN
$self->{config} = load_google_config($params->{config_file});
} elsif ($params->{config_json}) {
$self->{config} = decode_json $params->{config_json};
} else {
croak "config_file or config_json not provided in new()";
}
$self->{merchant_id} = $self->{config}->{merchant_id}
|| $params->{merchant_id}
|| croak "'merchant_id' not provided in json config in new()";
$self->{endpoint} = $self->{config}->{endpoint}
|| $params->{endpoint}
|| 'https://www.googleapis.com/content/v2';
$self->{debug} = 1 if $params->{debug};
$self->{google_auth_token} = get_google_auth_token($self);
$self->{rest} = init_rest_client($self);
return bless $self, $class;
}
sub get {
lib/Google/ContentAPI.pm view on Meta::CPAN
$method .= '/'. $opt->{resource} if $opt->{resource} ne '';
$method .= '/'. $opt->{method} if $opt->{method} ne '';
$method .= $encoded_params if $encoded_params;
return $method;
}
sub init_rest_client {
my $self = shift;
my $r = REST::Client->new();
$r->setHost($self->{endpoint});
$r->addHeader('Authorization', $self->{google_auth_token});
$r->addHeader('Content-type', 'application/json');
$r->addHeader('charset', 'UTF-8');
return $r;
}
sub request {
my $self = shift;
my @command = @_;
lib/Google/ContentAPI.pm view on Meta::CPAN
Authentication is done via Service Account credentials. See the following for details:
L<https://developers.google.com/shopping-content/v2/how-tos/service-accounts>
You will also need to create a Merchant Center Account:
L<https://developers.google.com/shopping-content/v2/quickstart>
For convenience, add your Merchant account ID to the *.json file provided by Google.
Your complete *.json file, after adding your merchant ID, will look something like this:
{
"endpoint": "https://www.googleapis.com/content/v2.1",
"merchant_id": "123456789",
"type": "service_account",
"project_id": "content-api-194321",
"private_key_id": "11b8e20c2540c788e98b49e623ae8167dc3e4a6f",
"private_key": "-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----\n",
"client_email": "google@content-api.iam.gserviceaccount.com",
"client_id": "999999999",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
lib/Google/ContentAPI.pm view on Meta::CPAN
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google%40content-api.iam.gserviceaccount.com"
}
=head1 SYNOPSIS
use Google::ContentAPI;
use Data::Dumper;
my $google = Google::ContentAPI->new({
endpoint => 'https://www.googleapis.com/content/v2.1',
debug => 0,
config_file => 'content-api-key.json',
config_json => $json_text,
merchant_id => '123456789',
});
my ($result, $products, $batch_id, $product_id);
# get account auth info (merchantId)
$result = $google->get(
lib/Google/ContentAPI.pm view on Meta::CPAN
);
print "$result->{code} ". ($result->{code} eq '200' ? 'success' : 'failure') ."\n";
print "Product status: \n". Dumper $result;
=head1 METHODS AND FUNCTIONS
=head2 new()
Create a new Google::ContentAPI object
=head3 endpoint
API endpoint to use.
v2.1 endpoint is 'https://www.googleapis.com/content/v2.1'.
v2.0 endpoint is 'https://www.googleapis.com/content/v2'.
If not provided, default to v2.0 endpoint for backwards compatibility.
=head3 debug
Displays API debug information
=head3 config_file
Path and filename of external C<.json> config file.
Either config_file or config_json must be provided. If both config_file
and config_json are provided, config_file will be used.
( run in 0.853 second using v1.01-cache-2.11-cpan-2b1a40005be )