I was able make to make push notification is working. I tested it on REST.
POST
Host: android.googleapis.com/gcm/send
Content-Type: application/json
Authorization: key=**apiKey**
Cache-Control: no-cache
Postman-Token: b33c61dc-a779-9198-bd96-aaf6c24fac6c
{
"data": {
"message": "hello world"
},
"registration_ids" : ["**deviceToken**"]
}
and my device got notification. Now I'm struggling to make parse push working.
POST localhost:7002/server/push
X-Parse-Application-Id: SSShop
X-Parse-Master-Key: 123
Content-Type: application/json
{
"where": {},
"data": {
"alert": "hello world 123"
}
}
the output: { result: true }, but notification is not received on device. Trying send push notification via Parse Dashboard and got output like this:
verbose: sending push to 2 installations
verbose: sent push! 0 success, 0 failures.
server.js:
const instance = {
appId: 'SSShop',
port: 7002,
serverURL: 'http://localhost:7002/server',
masterKey: '123',
databaseURI: 'mongodb://docker/ssshop',
publicServerURL: 'http://localhost:7002/server',
mountPath: '/server',
verifyUserEmails: true,
appName: 'SSShop',
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: 'XX',
domain: 'XX',
apiKey: 'XX'
}
},
push: {
android: {
senderId: "92014XXXXX",
apiKey: "**apiKey**"
}
}
}
package.json:
"parse": "~1.8.5",
"parse-dashboard": "~1.0.13",
"parse-server": "~2.2.11",
checking node_modules and got parse-server-push-adapter use version 1.0.4.
Related
I am trying to insert a LiveBroadcast using Youtube LIVE streaming API.
Here is my request which I made on the API playground on youtube API docs.
POST https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet%2C%20id%2C%20status%2C%20contentDetails&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"contentDetails": {
"enableClosedCaptions": true,
"enableEmbed": true,
"enableLowLatency": true,
"recordFromStart": true,
"enableAutoStart": true,
"enableAutoStop": true
},
"status": {
"privacyStatus": "public",
"selfDeclaredMadeForKids": true,
"liveBroadcastPriority": "high",
"madeForKids": true
},
"snippet": {
"title": "My broadcasst",
"description": "My Description",
"scheduledStartTime": "2020-06-177T03:48:46.46Z",
"scheduledEndTime": "2020-06-178T11:48:52.52Z"
}
}
And the response that I am getting is
{
"error": {
"code": 500,
"message": "Internal error encountered.",
"errors": [
{
"message": "Internal error encountered.",
"domain": "global",
"reason": "backendError"
}
],
"status": "INTERNAL"
}
}
Any help will be appreciated. Thanks in advance
The error was with the time format string that I had copied from google docs for ISO-8601 format, mentioned for all their time-relatedfields. I suggest creating your format string from here for java code
According to the docs, you're not supposed to provide the makeForKids property (that's the job of the API).
When calling for liveBroadcasts.insert endpoint, if wanting to designate the respective broadcast as child-directed, you should use this property instead:
status.selfDeclaredMadeForKids (boolean)
In a liveBroadcasts.insert request, this property allows the channel owner to designate the broadcast as being child-directed. In a liveBroadcasts.list request, the property value is only returned if the channel owner authorized the API request.
The other properties that you shouldn't have set are enableLowLatency and liveBroadcastPriority.
I setup a REST client with POST --> https://fcm.googleapis.com/fcm/send
Content-Type : application/json
Authorization : key=<server-key>
JSON Body:
{
"to": "testTopic",
"data": {
"key1" : "val1",
"key2" : true
}
}
The repsonse in 200 OK but the response body has:
{
"multicast_id": 6098503498585,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results":[
{
"error": "InvalidRegistration"
}
]
}
So the onMessageReceived() is not triggered, neither app in foreground nor in background? Why do I get InvalidRegistration ? What am I missing?
The server key at point 3 is from Firebase Project settings --> Cloud messaging --> Server key
In 4. your JSON requires a preceeding
/topics/
for "to" thus:
{ "to": "/topics/testTopic",....}
i am coding an Api Rest in rails 5, using gem 'fcm' to send notifications. I have already configure firebase in my android app and I can send notifications successfully from the Firebase console, but from my rails api i cannot receive the notificacion in my device, this is my code:
this is my rails controller:
class AccionesController < ApplicationController
def enviar
require 'fcm'
fcm = FCM.new("AAAAlBfTsV4:AheregoesmySERVEKEYsXXm-vQGfMjVuo8TpYrApHsnGU4ZasdfajsdfñalUtf26LeND4U4lXFZZplpzJjTWoiisWP-Esl5afCSTmiDI9y5gP6OObqY76NVcOn9ceaIUGMZ")
# fcm = FCM.new("my_server_key", timeout: 3)
registration_ids= [params[:devicetoken]] # an array of one or more client registration tokens
options = {data: {score: "mynewscore"},
notification: {
title: "Message Title",
body: "Hi, Worked perfectly",
icon: "myicon"}
,collapse_key: "testeando desde rails", priority: "high"}
response = fcm.send(registration_ids, options)
render json: response
end
def noti_params
params.permit(:devicetoken)
end
end
I execute from Postman this is the route that execute the controller:
http://localhost:3000/acciones/enviar?here goes the device token as parameter
And, here is the response:
{"body":"{\"multicast_id\":5276983113254623155,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1502991819420287%2293308c2293308c\"}]}","headers":{"content-type":["application/json;
charset=UTF-8"],"date":["Thu, 17 Aug 2017 17:43:39
GMT"],"expires":["Thu, 17 Aug 2017 17:43:39
GMT"],"cache-control":["private,
max-age=0"],"x-content-type-options":["nosniff"],"x-frame-options":["SAMEORIGIN"],"x-xss-protection":["1;
mode=block"],"server":["GSE"],"alt-svc":["quic=\":443\"; ma=2592000;
v=\"39,38,37,35\""],"accept-ranges":["none"],"vary":["Accept-Encoding"],"connection":["close"]},"status_code":200,"response":"success","canonical_ids":[],"not_registered_ids":[]}
the response shows success: 1 and status code: 200 but the notification never reaches the device,and the firebase console does not show the message.
Am I missing something?
please help?
or is there another way or ruby gem to send notification with a clear example?
any suggestions are welcome... thanks in advance
Instead of using fcm gem, you can also use RestClient gem. The usage for fcm notifications is as follow.One thing to note is if the payload is passing using ".to_json", the header content type also must be specified as json. Hope this help.
def self.send_noti(device_token)
options = data().merge ({"to": "#{device_token}"})
RestClient.post("https://fcm.googleapis.com/fcm/send", options.to_json, headers={'Content-Type' => 'application/json','Authorization' => "key=#{ENV['fcm_token']}"})
end
def self.data()
options = {
"notification": {
"body": "Your noti body",
"title": "Your noti title"
},
"data": {
"d1": "Your data" #can be any, d1, status or whatever
}
}
end
rest-client gem
fcm_client = FCM.new(your_firebase_key)
registration_ids= [user_device_token]
options = {
priority: 'high',
data: {
message: "Hai",
location: location
},
notification: {
body: "Hai",
location: "location",
sound: 'default'
}
}
fcm_client.send(registration_ids, options)
end
end
try this message options because the error should be your notification syntax.
options = {
priority: 'high',
data: {
message: "Hai",
location: location
},
notification: {
body: "Hai",
location: "location",
sound: 'default'
}
}
Hi i have self hosted parse server on digital ocean, it is sending notifications on iOS but not on android. my index.js file looks like this:
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://1.1.1.1"1/app_name',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: 'abc',
masterKey: 'def',
serverURL: 'http://1.1.1.1:1337/parse' || 'http://localhost:1337/parse',
verbose: true,
push: {
android:{
senderId: 'my FCM id',
apiKey: 'my FCM key'
},
ios: {
pfx: '1',
bundleId: '2',
production: true
}
}
});
when i send a push from the parse dashboard (also self hosted), this is the response i get with verbose:true:
"results": [
{
"objectId": "bNtZqwY8",
"pushTime": "2017-06-13T10:49:06.095Z",
"query": "{\"UniqueId\":\"c49de788ce\",\"deviceType\":{\"$in\":[\"android\"]}}",
"payload": "{\"alert\":\"Thank you for using my app.\"}",
"source": "rest",
"status": "succeeded",
"numSent": 0,
"pushHash": "266b6b637152b36040830",
"createdAt": "2017-06-13T10:49:06.095Z",
"updatedAt": "2017-06-13T10:49:06.214Z",
"numFailed": 15,
"failedPerType": {
"android": 15
},
"ACL": {}
},
{
"objectId": "rsYinvGG",
"pushTime": "2017-06-13T10:48:42.449Z",
"query": "{\"UniqueId\":\"7A0A-9AEA-5870FDEC42A3\"}",
"payload": "{\"alert\":\"one\",\"link_key\":1,\"sound\":\"default\"}",
"source": "rest",
"status": "succeeded",
"numSent": 2,
"pushHash": "246431e019c0357dcb180c7",
"createdAt": "2017-06-13T10:48:42.449Z",
"updatedAt": "2017-06-13T10:48:43.282Z",
"numFailed": 0,
"sentPerType": {
"ios": 2
},
"ACL": {}
},
When i send push on android from FCM, it works. Im really lost here with android push, can someone please point me in the right direction.
Here is the output from the log:
ESC[36mverboseESC[39m: REQUEST for [PUT] /parse/classes/_Installation /zKIp8LLOWr: {
"GCMSenderId":"diMV6Hm3j07dbqVPEsZRgqNzDo3YvA5zNdUmtO6Q4ka5ijRyyIRHiWCWOBVBDA22OIls-4bO06kxDPuOKFwJUZuMD3Xt41WuKUoOJwBlW7cKdqv9llj7Me0uiWFLWDwS7V",
"UniqueId": "a59020fff8ca30d00",
"appVersion": "2.3.3",
"objectId": "zKIp8LLOWr"
} method=PUT, url=/parse/classes/_Installation/zKIp8LLOWr, x-parse- app-display-version=2.3.3, x-parse-installation-id=29918e2f-8bbd-4ab7-975f-f854e1f43689, user-agent=Parse Android SDK 1.13.1 (com.mrfizzy/18) API Level 21, connection=Keep-Alive, accept-encoding=gzip, x-parse-os-version=5.0, x-parse-app-build-version=18, content-type=application/json, x-parse-client-key=, x-parse-client-version=a1.13.1, host=46.101.199.219:1337, content-length=245, x-parse-application-id=JHyfl9YhXCQ24r6J8ohdVlHLt1hfWhB4MF2jQAQn, GCMSenderId=diMV6HmLH3I:APA91bFQS4Sq9G5wlej07dbqVPEsZRgqNzDo3YvA5zNdUmtO6Q4ka5ijRyyIRHiWCWOBVBDA22OIls-4bO06kxDPuOKFwJUZuMD3Xt41WuKUoOJwBlW7cKdqv9llj7Me0uiWFLWDwS7V, UniqueId=a59020a48ca30d00, appVersion=2.3.3, objectId=zKIp8LLOWr
ESC[31merrorESC[39m: Error generating response. ParseError { code: 101, message: 'Object not found for update.' } code=101, message=Object not found for update.
[object Object]
It appears you're not assigning the Sender Id properly. You're passing an objectId that doesn't seem to be correct. Make sure you use ParseInstallation.getCurrentInstallation() when you set your GCM sender id rather than trying to get the installation by any other means.
http://parseplatform.org/Parse-SDK-Android/api/com/parse/ParseInstallation.html#getCurrentInstallation()
My application does post request to url:
https://myserver.domain.com/authenticate/credentials
OkHttp client interceptor shows my headers:
11-17 10:10:56.780 3140-3304/com.myapp.debug D/OkHttp: Content-Type:
application/x-www-form-urlencoded
11-17 10:10:56.780 3140-3304/com.myapp.debug D/OkHttp: Content-Length:
187
11-17 10:10:56.781 3140-3304/com.myapp.debug D/OkHttp: Authorization:
Basic authorisationkeyfortest5430593045903495034905==
11-17 10:10:56.781 3140-3304/com.myapp.debug D/OkHttp:
email=testlogin%40gmail.com&password=test%4012&deviceId=1484564155&deviceLabel=Android%20SDK%20built%20for%20x86_64&deviceType=ANDROID&deviceVersion=23%20%28REL%29
I have created standalone WireMock server and I want redirect every POST request from my APP to my WireMock server. Thats why I have added *.JSON with request definition:
{
"request": {
"method": "POST",
"urlPattern": ".*"
},
"response": {
"proxyBaseUrl" : "https://myserver.domain.com/",
"additionalProxyRequestHeaders": {
"Authorization": "Basic authorisationkeyfortest5430593045903495034905== "
}
}
}
What I expect that should happen:
When I change basepath of my Http client from https://myserver.domain.com/ to http://myserveraddress.com/ - then every request from my app should go to my MockServer. And MockServer according to JSON above should proxy/forward that request to https://myserver.domain.com/ and return the same response - so everything should work fine.
What happens:
Each POST request returns status 200 but body is empty. (it should return authenticated user object)
Question: Is it possible to achieve that? Am I doing something wrong?
Try to add your body in "__files" folder and set path in "bodyFileName"
{
"request": {
"method": "POST",
"urlPattern": ".*"
},
"response": {
"proxyBaseUrl" : "https://myserver.domain.com/",
"additionalProxyRequestHeaders": {
"Authorization": "Basic authorisationkeyfortest5430593045903495034905== "
},
"bodyFileName":".*.json"
}
In JSON file put your answer. For example:
{
"errorCode": 0,
"errorMessage": "",
"result":
{
"filed1":"value",
"filed2":"value"
}
}