-
Notifications
You must be signed in to change notification settings - Fork 133
/
SharedDb.gs
32 lines (25 loc) · 935 Bytes
/
SharedDb.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var db = ScriptDb.getMyDb();
function getDb(){
return db;
}
function sendGCM(msg){
msg = msg || 'hello world!'; //give default message for debugging
var regIds = [];
var result = db.query({});
while (result.hasNext()) {
var current = result.next();
regIds.push(current.regId);
}
var apiKey = 'YOUR_API_KEY';
var payload = {'registration_ids' : regIds,
'data' : {
'message' : msg
}};
var urlFetchOptions = {'contentType' : 'application/json',
'headers' : {'Authorization' : 'key=' + apiKey},
'method' : 'post',
'payload' : JSON.stringify(payload)};
var gcmUrl = 'https://android.googleapis.com/gcm/send';
var response = UrlFetchApp.fetch(gcmUrl,urlFetchOptions).getContentText()
Logger.log(response);//for testing purposes. improve error handling here
}