Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showing push error #1394

Closed
apurvaaggarwal opened this issue Apr 6, 2016 · 35 comments
Closed

showing push error #1394

apurvaaggarwal opened this issue Apr 6, 2016 · 35 comments

Comments

@apurvaaggarwal
Copy link

Android Code:
final Map<String, Object> params = new HashMap<>();
params.put("message", message);
params.put("userId", ParseUser.getCurrentUser().getObjectId());

ParseCloud.callFunctionInBackground("sendPush", params,
        new FunctionCallback<String>() {
            @Override
            public void done(String result, com.parse.ParseException e) {
                // TODO Auto-generated method stub

                if (e == null) {
                    Toast.makeText(context, "HEHE", Toast.LENGTH_SHORT)
                            .show();
                    Log.d("ANNOUNCEMENT", "SUCCESS");
                } else {
                    Toast.makeText(context, "FAilure " + e.toString(),
                            Toast.LENGTH_SHORT).show();

                    Log.d("ANNOUNCEMENT", "FAILURE" + e.toString());
                }
            }
        });

///////////////////////////////////////////////
main.js
Parse.Cloud.define("sendPush", function(request, response) {

var sendUserId = request.params.userId;
var msg = request.params.message;

var query = new Parse.Query(Parse.Installation);
query.equalTo('userId', sendUserId);

Parse.Push.send({
        where: query,
        data: {
                alert: msg,
                sound: 'default'
        }
}, {
        success: function() {
                // Push was successful
                response.success("Push sent");
        },
        error: function(error) {
                // Handle error
                response.error(error);
        },
        useMasterKey: true
});

});
But not getting push
Here is the verbose //////
verbose: sending push to 1 installations
verbose: sent push! 0 success, 0 failures

@flovilmart
Copy link
Contributor

What adapter are you using? Which devices are you sending to? Android, iOS? Can you get the _PushStatus object?

@apurvaaggarwal
Copy link
Author

I am using parse push adapter; sending to android devices

_PushStatus

{
"_id" : ObjectId("5704f607c87f874d22157520"),
"objectId" : "AJDiHp7HRu",
"pushTime" : "2016-04-06T11:41:59.478Z",
"_created_at" : ISODate("2016-04-06T11:41:59.478+0000"),
"query" : "{"objectId":"rJvrh1s0BH"}",
"payload" : {
"alert" : "4",
"sound" : "default"
},
"source" : "rest",
"title" : null,
"expiry" : null,
"status" : "succeeded",
"numSent" : NumberInt(0),
"pushHash" : "01538e1dfb45c0adc1c4bd63365cf403",
"_wperm" : [

], 
"_rperm" : [

], 
"numFailed" : NumberInt(0)

}

@flovilmart
Copy link
Contributor

I'll have a look. what version of parse-server are you using?

@apurvaaggarwal
Copy link
Author

2.2.6

@flovilmart
Copy link
Contributor

thanks. It seems to be the parse-server-push-adapter that is not reporting correctly the statuses of the pushes.

@flovilmart
Copy link
Contributor

When running with VERBOSE=1, you should have that kind of logs:

verb parse-server-push-adapter GCM sending to 1 device
verb parse-server-push-adapter GCM GCM Response: {
verb parse-server-push-adapter GCM     "multicast_id": 8389764779291095000,
verb parse-server-push-adapter GCM     "success": 0,
verb parse-server-push-adapter GCM     "failure": 1,
verb parse-server-push-adapter GCM     "canonical_ids": 0,
verb parse-server-push-adapter GCM     "results": [
verb parse-server-push-adapter GCM         {
verb parse-server-push-adapter GCM             "error": "InvalidRegistration"
verb parse-server-push-adapter GCM         }
verb parse-server-push-adapter GCM     ]
verb parse-server-push-adapter GCM }

Can you please provide them?

@apurvaaggarwal
Copy link
Author

verbose: POST /parse/push { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.1 (NodeJS 5.3.0)',
accept: '/',
'content-type': 'text/plain',
host: '166.62.82.202:1337',
'content-length': '278',
connection: 'close' } {
"where": {
"objectId": "KQPONXtIjb"
},
"data": {
"alert": "Hello",
"sound": "default"
}
}
verbose: {
"response": {
"result": true
}
}
success
verbose: {
"response": {
"result": "Push sent "
}
}
verbose: sending push to 1 installations
verbose: sent push! 0 success, 0 failures

i am getting this when i run using VERBOSE

@flovilmart
Copy link
Contributor

Seems to be a misconfiguration in parse-server-push adapter, how did you set it up?

@apurvaaggarwal
Copy link
Author

i have set it up in index.js using google project number and sender api key

@flovilmart
Copy link
Contributor

Would you care to show it?

@apurvaaggarwal
Copy link
Author

untitlednew

@flovilmart
Copy link
Contributor

what's the version of parse-server-push-adapter? in node_modules/parse-server-push-adapter/package.json

@apurvaaggarwal
Copy link
Author

1.0.4

@ghost
Copy link

ghost commented Apr 7, 2016

Is end of ',' in emailAdapter-apiKey and push line relate this bug?

emailAdapter
emailAdapter : {
 ....
      options : {
              ....
              apiKey: 'YOUR_KEY' ,  // no references but you added ',' .
      }
}
....
push
....
push: {
       android : {
          .....
        }
    }  ,   // also added here.
});  // end of parse server configuration

@apurvaaggarwal
Copy link
Author

@estylehq elborate please

@ghost
Copy link

ghost commented Apr 7, 2016

updated.

I think that isn't cause this prob. maybe. :(

@apurvaaggarwal
Copy link
Author

means in my index file i have remove the comma that i have instered at the end of the email adapter

@ghost
Copy link

ghost commented Apr 7, 2016

yeah. and end of push configuration too.

@apurvaaggarwal
Copy link
Author

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://myadreees:27017/test',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID ||'apkeykey',
masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://myadreees/parse', // Don't forget to change to https if needed

verifyUserEmails:true,
publicServerURL:'http://myadreees:1337/parse',
appName: 'Trakie',
emailAdapter:{
module: 'parse-server-simple-mailgun-adapter',
options:{
fromAddress:'',
domain:'',
apiKey:'',}},
push: {
android: {
senderId:'',
apiKey:''
}
},
});

/??//// is this correct

@ghost
Copy link

ghost commented Apr 7, 2016

remove comma end of push config.

@apurvaaggarwal
Copy link
Author

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://myadreees:27017/test',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID ||'apkeykey',
masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://myadreees/parse', // Don't forget to change to https if needed

verifyUserEmails:true,
publicServerURL:'http://myadreees:1337/parse',
appName: 'Trakie',
emailAdapter:{
module: 'parse-server-simple-mailgun-adapter',
options:{
fromAddress:'',
domain:'',
apiKey:'',}},
push: {
android: {
senderId:'',
apiKey:''
}
}
});

@apurvaaggarwal
Copy link
Author

Updated index.js but the error is still same

@flovilmart
Copy link
Contributor

can you please format correctly your index.js configuration? It's impossible to see where your error is.... Also we have many users having a functional push setup.

@apurvaaggarwal
Copy link
Author

i have reformated the code of index.js and can you tell me that if want to send push to a specfic user using the object id of that users

@flovilmart
Copy link
Contributor

That question should be asked over stackoverlow, or any other forum. We're not here to provide support for your implementations.

@apurvaaggarwal
Copy link
Author

ok will the client push enable in future use

@flovilmart
Copy link
Contributor

I don't believe it will ever be enable as this is a very important security problem. Also, many users have worked around it by creating a cloud code function. Look through the issues, and other references, and you should be good to go.

Coming back to your issue, can we have a properly formatted index.js?

@apurvaaggarwal
Copy link
Author

yes i have formatted it here it is
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID ||'',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http', // Don't forget to change to https if needed

verifyUserEmails:true,
publicServerURL:'http:',
appName: 'Trakie',
emailAdapter:{
module: 'parse-server-simple-mailgun-adapter',
options:{
fromAddress:'@gmail.com',
domain:'.mailgun.org',
apiKey:'key-',}},
push: {
android: {
senderId:'',
apiKey:''
}
}
});

@flovilmart
Copy link
Contributor

this is not formatted....

formatted is:

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb',
  emailAdapter:{
    module: 'parse-server-simple-mailgun-adapter',
    options:{
      fromAddress:'@gmail.com',
      domain:'.mailgun.org',
      apiKey:'key-'
    }
  }
})

@apurvaaggarwal
Copy link
Author

then what about push notification adapter

@flovilmart
Copy link
Contributor

what do you mean?

@apurvaaggarwal
Copy link
Author

in index,js we have to declare both push adapter , email adapter and server info(master key,app id,mongo db connection string) then the formateed code that have been provided in that where i would add push adapter

@flovilmart
Copy link
Contributor

this was just an example, to show you how to properly format the code when you share it. Your shared file appear all flat, with multiple } on certain lines... I can't really say what's wrong in your configuration because it's just plain ugly and not readable

@apurvaaggarwal
Copy link
Author

i have checked everything again but the problem is steill there
here is my main,js file
Parse.Cloud.define("sendPush2", function(request, response) {

var sendUserId = request.params.userId;
    var msg = request.params.message;

var query = new Parse.Query(Parse.User);
query.equalTo("ObjectId", id);

    Parse.Push.send({
       where : query,
            data: {

                    alert: "msg"

            }
    }, {

useMasterKey:true,
success: function() {
// Push was successful
console.log("success");
response.success("Push sent ");
},
error: function(error) {
// Handle error
console.log("failed");
response.error(error);
}

    });

});

@flovilmart
Copy link
Contributor

the query on push should be on Parse.Installation not on Parse.User... That's why you're not getting anything...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants