Closed faraz9x closed 5 years ago
So fetch the devices list and take the ID: $devices = $api->devices->getAll();
how i know which is the id of current device
It's impossible because in backend there is no "current device"
okay, i meant any how whether in backend or front end, we can get current device / player id for onesignal in javascript:
OneSignal.push(["getUserId", function(useridi) { alert("USERID:"+ useridi); }]);
I would suggest you to set the user email https://documentation.onesignal.com/docs/web-push-sdk#section--synchashedemail- to onesignal and then in backend target the users by email
Or just assign the device ID to the backend user
Is it not a posibility to create a backend REST API with something like a $_POST request to the server in order to send the user's player id or device id to the server, Save that in your backend and then push it to that specific device whenever needed? This scenario is in case the user wants to create push notifications with specific dates from within their frontend. Not sure if that's what faraz9x wanted, but definitly something I want to have.
EDIT: I realize now that the onesignal SDK has such functionality and there is no need to do this on the backend... My mistake.
:) also this is business logic and not the library responsibility.
@faraz9x @Simbaclaws
Hi,
I am starting to do this I was wondering how you got this to work in the end?
How can I link a User to a list of devices?
@eqxDev pass the user information to your frontend from backend somehow and then add tags:
OneSignal.sendTag('user_id', this.user.id);
OneSignal.sendTag('real_name', this.user.fullName);
OneSignal.syncHashedEmail(this.user.email);
then you'll be able to target users by these tags from backend, I am using like this in my cordova application
Thanks @norkunas what will I use the tags for? Can I set them to anything?
Also does one signal has its own user-agent I can detect?
Tags are good for direct targeting, for example let's say if you are sending some message to the user in your system and if user subscribed to get push notifications, then you can target onesignal notification by the user ID and he will receive notification that you sent message for him.
Tags can be anything but must be in a String format.
About the last question, could you explain further?
@eqxDev yeah onesignal will create a unique device id for all registered devices but the fact that same user can use the application from multiple devices makes us use tags
and tags can be set from both front end (JS SDK) and from backend (REST API).
Using JavaScript how would I get the uuid of device so I can use AJAX to send it to the database?
@eqxDev https://stackoverflow.com/a/42923420/1815160 try this :)
Please guide, How to get current device or player id.