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

getting an error when sending push to multiple recipientIds #1373

Closed
apurvaaggarwal opened this issue Apr 5, 2016 · 31 comments
Closed

getting an error when sending push to multiple recipientIds #1373

apurvaaggarwal opened this issue Apr 5, 2016 · 31 comments

Comments

@apurvaaggarwal
Copy link

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({
            query: 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
    });

});

/////// Android Code

public static void sendPush(final Context context, String message, String senderId) {

// String channel = "parse_user_channel_";
final Map<String, Object> params = new HashMap<>();
// params.put("accountId", channel);
params.put("message", message);
// params.put("senderName", senderName);
params.put("userId", senderId);
// params.put("useMasterKey", true);//Must have this line

  ParseCloud.callFunctionInBackground("sendPush", params, new FunctionCallback<String>() {

// public void done(String result, ParseException e) {
// 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());
// }
// }

    @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());
         }
    }
  });

}
//////Errorr

FAILUREcom.parse.ParseRequest$ParseRequestException: {"code":115,"message":"Channels and query should be set at least one."}

@ghost
Copy link

ghost commented Apr 5, 2016

use 'where'.
....
query : query -> where : query
....
see this document : https://parse.com/docs/js/guide#push-notifications

@apurvaaggarwal
Copy link
Author

Elaborate plz!!!!!!

@ghost
Copy link

ghost commented Apr 5, 2016

... Parse.Push.send({ query: query, data: { alert: msg, sound: 'default' } } ....
to
... Parse.Push.send({ where: query, data: { alert: msg, sound: 'default' } } ....

@apurvaaggarwal
Copy link
Author

Thank you for the previous query....it almost worked...:)
If I want to send push to multiple users ...Is that possible?

@ghost
Copy link

ghost commented Apr 5, 2016

It has to ways : use ParsePromise, or use querying with array.

If you want to use Promise, you will send different message(maybe).
-> reference is here : https://parse.com/docs/js/guide#promises-promises-in-parallel

This reference use '_' (underscore), parse server is not support.

replace for each.

@apurvaaggarwal
Copy link
Author

What is the way of using it with " querying with array"?

@ghost
Copy link

ghost commented Apr 5, 2016

Oops. It's not supported that. Sorry.

Using promise is best solution, for now (or for me).

@apurvaaggarwal
Copy link
Author

Okay...thanks .. I ll try to configure it and come back with the problems...:)
Can I send push to multiple channels as well ?

@ghost
Copy link

ghost commented Apr 5, 2016

I'm not sure, cause I'm not use channel yet.

But using channel is more easier to send people same message.

@apurvaaggarwal
Copy link
Author

ok thanks for helping me out

@apurvaaggarwal
Copy link
Author

Sir i changed this
... Parse.Push.send({ query: query, data: { alert: msg, sound: 'default' } } ....
to
... Parse.Push.send({ where: query, data: { alert: msg, sound: 'default' } } ....
......but in _pushstatus it is showing running (status)

@ghost
Copy link

ghost commented Apr 5, 2016

logs

@apurvaaggarwal
Copy link
Author

{
"_id" : ObjectId("5703a8a90ac1a5882c3b4008"),
"objectId" : "di4FL8PPCv",
"pushTime" : "2016-04-05T11:59:37.354Z",
"_created_at" : ISODate("2016-04-05T11:59:37.354+0000"),
"query" : "{"userId":"4tKMN1HctW"}",
"payload" : {
"alert" : "5",
"sound" : "default"
},
"source" : "rest",
"title" : null,
"expiry" : null,
"status" : "running",
"numSent" : NumberInt(0),
"pushHash" : "6e4b2efabbfd5b883b9baf5ac78faf5b",
"_wperm" : [

], 
"_rperm" : [

]

}

@flovilmart
Copy link
Contributor

The push status never gets updated?

@HemanParbhakar
Copy link

yes it never gets updated

@flovilmart
Copy link
Contributor

can you run with VERBOSE=1? what version of parse-server are you running, since 2.2.5 (released yesterday) we improved the tracking of push errors and reporting

@HemanParbhakar
Copy link

can u tell in detail how to do that

@flovilmart
Copy link
Contributor

update or set an environment variable? for the update, just run npm update parse-server for the environment, given you're on mac or linux that would be VERBOSE=1 (your command to start parse-server)

@HemanParbhakar
Copy link

can u please provide me an example link i am not gettign what are u saying

@flovilmart
Copy link
Contributor

@HemanParbhakar
Copy link

i have updated it but it does not change anything

@flovilmart
Copy link
Contributor

can you please provide the logs when running with VERBOSE=1?

@HemanParbhakar
Copy link

i ran parse server using command "npm start " where i have to use verbose=1

@flovilmart
Copy link
Contributor

run: VERBOSE=1 npm start

@HemanParbhakar
Copy link

ok

@HemanParbhakar
Copy link

here is the verbose ...

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': '276',
connection: 'close' } {
"where": {
"userId": "5ZMHufuKzr"
},
"data": {
"alert": "Hello",
"sound": "default"
}
}
verbose: {
"response": {
"result": true
}
}
success
verbose: {
"response": {
"result": "Push sent "
}
}
verbose: sending push to 0 installations
verbose: sent push! 0 success, 0 failures

@flovilmart
Copy link
Contributor

Seems that your query is malformed as verbose: sending push to 0 installations indicates

@HemanParbhakar
Copy link

here is my cloud code

untitledmmkmk

@flovilmart
Copy link
Contributor

Does your query returns installations? I don't think so, given the logs...
Again, the github issues are not a support channel for debugging your code. Please ask over stackoverflow

@HemanParbhakar
Copy link

where is the error can u elaborate

@flovilmart
Copy link
Contributor

@Heman6886 ask over http://stackoverflow.com/ please as this is an implementation issue on your side and not an issue on parse-server. Thanks.

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

3 participants