https://github.com/pavelsr/api-google
https://metacpan.org/pod/WebService::GoogleAPI::Client
https://github.com/pavelsr/api-google
google-api offline-mode perl
Last synced: over 1 year ago
JSON representation
https://metacpan.org/pod/WebService::GoogleAPI::Client
- Host: GitHub
- URL: https://github.com/pavelsr/api-google
- Owner: pavelsr
- Created: 2016-11-09T21:12:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-29T18:06:57.000Z (almost 4 years ago)
- Last Synced: 2023-08-20T22:28:22.395Z (almost 3 years ago)
- Topics: google-api, offline-mode, perl
- Language: Perl
- Homepage: https://metacpan.org/pod/API::Google
- Size: 27.3 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NAME
API::Google - Perl library for easy access to Google services via their API
# VERSION
version 0.12
# SYNOPSIS
use API::Google;
my $gapi = API::Google->new({ tokensfile => 'config.json' });
$gapi->refresh_access_token_silent('someuser@gmail.com');
$gapi->api_query({
method => 'post',
route => 'https://www.googleapis.com/calendar/v3/calendars/'.$calendar_id.'/events',
user => 'someuser@gmail.com'
}, $json_payload_if_post);
# CONFIGURATION
config.json must be structured like:
{ "gapi":
{
"client_id": "001122334455-abcdefghijklmnopqrstuvwxyz012345.apps.googleusercontent.com",
"client_secret": "1ayL76NlEKjj85eZOipFZkyM",
"tokens": {
"email_1@gmail.com": {
"refresh_token": "1/cI5jWSVnsUyCbasCQpDmz8uhQyfnWWphxvb1ST3oTHE",
"access_token": "ya29.Ci-KA8aJYEAyZoxkMsYbbU9H_zj2t9-7u1aKUtrOtak3pDhJvCEPIdkW-xg2lRQdrA"
},
"email_2@gmail.com": {
"access_token": "ya29.Ci-KAzT9JpaPriZ-ugON4FnANBXZexTZOz-E6U4M-hjplbIcMYpTbo0AmGV__tV5FA",
"refresh_token": "1/_37lsRFSRaUJkAAAuJIRXRUueft5eLWaIsJ0lkJmEMU"
}
}
}
}
You can easily generate such config with goauth CLI tool inluded in this package
# SUBROUTINES/METHODS
## refresh\_access\_token\_silent
Get new access token for user from Google API server and store it in jsonfile
## build\_headers
Keep access\_token in headers always actual
$gapi->build_http_transactio($user);
## build\_http\_transaction
$gapi->build_http_transaction({
user => 'someuser@gmail.com',
method => 'post',
route => 'https://www.googleapis.com/calendar/users/me/calendarList',
payload => { key => value }
})
## api\_query
Low-level method that can make API query to any Google service
Required params: method, route, user
Examples of usage:
$gapi->api_query({
method => 'get',
route => 'https://www.googleapis.com/calendar/users/me/calendarList'',
user => 'someuser@gmail.com'
});
$gapi->api_query({
method => 'post',
route => 'https://www.googleapis.com/calendar/v3/calendars/'.$calendar_id.'/events',
user => 'someuser@gmail.com'
}, $json_payload_if_post);
# AUTHOR
Pavel Serikov
# COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Pavel Serikov.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.