Skip to content

Instantly share code, notes, and snippets.

@faried
Created January 31, 2017 17:49
Show Gist options
  • Save faried/cc0d05472f72558fb34d8757cc74e068 to your computer and use it in GitHub Desktop.
Save faried/cc0d05472f72558fb34d8757cc74e068 to your computer and use it in GitHub Desktop.
using the dart firebase package on my laptop.
/*
* pubspec.yaml:
*
* name: dconsole1
* version: 0.0.1
* description: A simple console application.
* dependencies:
* firebase: '^3.0.0'
* http: '^0.11.3'
* googleapis_auth: any
*
* CREDENTIALS is a file downloaded from
* https://console.firebase.google.com/ => your project => gear =>
* project settings => service accounts => generate new private key
*/
import 'dart:io';
import 'package:googleapis_auth/auth_io.dart';
import 'package:firebase/firebase_io.dart';
const String CREDENTIALS = "project-42-firebase-adminsdk-2ftwd-something.json";
const String PATH = "https://project-42.firebaseio.com/messages.json";
final List<String> SCOPES = [
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/userinfo.email"];
main(List<String> args) {
print('Hello world!');
// withFutures();
withA();
}
void withFutures() {
final File credsfile = new File(CREDENTIALS);
credsfile.readAsString().then((contents) {
final credentials = new ServiceAccountCredentials.fromJson(contents);
clientViaServiceAccount(credentials, SCOPES).then((client) {
var fb = new FirebaseClient(client.credentials.accessToken.data);
fb.get(PATH).then((thing) => print(thing));
client.close();
});
});
}
withA() async {
final File credsfile = new File(CREDENTIALS);
final contents = await credsfile.readAsString();
final credentials = new ServiceAccountCredentials.fromJson(contents);
final client = await clientViaServiceAccount(credentials, SCOPES);
final fb = new FirebaseClient(client.credentials.accessToken.data);
var data = await fb.get(PATH);
// type is _InternalLinkedHashMap
print(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment