from __future__ import print_function
import json
import apiclient
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
class Firebase(object):
def __init__(self,keyFile):
self._scopes = ['https://www.googleapis.com/auth/firebase.database']
self._credentials = ServiceAccountCredentials.from_json_keyfile_name(keyFile,self._scopes)
print(self._credentials.get_access_token())
g=Firebase('config/SHORTURL-71318685345b.json')
$ py firebase.py
AccessTokenInfo(access_token='ya29.CjD1AtWK0psCP-uj-n_k2cxhM9MTut1jfDG_-FLWNTkvkeh_KmPUoPu8DvtwhZN7_YM', expires_in=3600)
$ curl https://shorturl-1267.firebaseio.com/.json?access_token=ya29.CjD1AtWK0psCP-uj-n_k2cxhM9MTut1jfDG_-FLWNTkvkeh_KmPUoPu8DvtwhZN7_YM
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 37 100 37 0 0 57 0 --:--:-- --:--:-- --:--:-- 57{
"error" : "Permission denied."
}
class ShortUrl(object):
def __init__(self,keyFile):
self._scopes = ['https://www.googleapis.com/auth/urlshortener']
self._credentials = ServiceAccountCredentials.from_json_keyfile_name(keyFile,self._scopes)
print(self._credentials.get_access_token())
g=ShortUrl('config/SHORTURL-71318685345b.json')
$ py shorturl.pyAccessTokenInfo(access_token='ya29.CjP1Aqd4nU3cGtl8k_m7FSU8kdRxgOmAR-lkWi0862fVhTBysv3wWlvbdo_tWFGXzs1GNGw', expires_in=3600)
$ curl https://www.googleapis.com/urlshortener/v1/url/history?access_token=ya29.CjP1Aqd4nU3cGtl8k_m7FSU8kdRxgOmAR-lkWi0862fVhTBysv3wWlvbdo_tWFGXzs1GNGw
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3828 100 3828 0 0 9428 0 --:--:-- --:--:-- --:--:-- 9428{
"kind": "urlshortener#urlHistory",
"totalItems": 21,
"itemsPerPage": 30,
"items": [
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/1dad4c46-919d-49a9-b5be-863d97fb6c91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class Firebase(object):
def __init__(self,keyFile):
self._API_KEY = 'AIzaSyAwWRMFi_l5PStENHDn1i8QF060T_Hdc-k'
self._scopes = ['https://www.googleapis.com/auth/firebase.database']
self._credentials = ServiceAccountCredentials.from_json_keyfile_name(keyFile,self._scopes)
h = self._credentials.authorize(httplib2.Http())
print(self._credentials.get_access_token())
print(h.request.credentials.get_access_token())
g=Firebase('config/SHORTURL-71318685345a.json')
$ py firebase.py
AccessTokenInfo(access_token='ya29.CjD1AvvkPqskoxKsoIZVq6mI74Q1EPhJgL6LWsAyNIhm8n8YNJ59I0iqqJwtwELO0SM', expires_in=3600)
AccessTokenInfo(access_token='ya29.CjD1AvvkPqskoxKsoIZVq6mI74Q1EPhJgL6LWsAyNIhm8n8YNJ59I0iqqJwtwELO0SM', expires_in=3599)
GoogleCredential googleCred = GoogleCredential.fromStream(new FileInputStream("service_account.json"));
GoogleCredential scoped = googleCred.createScoped(
Arrays.asList("https://www.googleapis.com/auth/firebase.database"));
scoped.refreshToken();
String token = scoped.getAccessToken();
curl 'https://samplechat.firebaseio-demo.com/users/jack/name.json?access_token=<TOKEN>'
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d273992c-1928-4475-a7da-f9834d984482%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/0c8bbdc4-ff56-4715-a3b5-5e5fb5cb8b1a%40googlegroups.com.
{
"iss":"blab...@blablabla.iam.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email",
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp":<unix timestamp of max request time, max 3600 seconds in the future>,
"iat":<unix timestamp of 'now'>
}