[OneSignal Plugin] How to get player id of device

[OneSignal Plugin] How to get player id of device

  
Forge Component
(5)
Published on 27 Apr by OutSystems R&D
5 votes
Published on 27 Apr by OutSystems R&D

I want to be able to send notifications to individual users. I am indeed able to, if I log into the OneSignal dashboard and find the player id of a certain device, but how can I get the player id within the app using the plugin?

I tried the RegisterWithUser action but the instructions on this page are extremely vague. The action succeeds, but then what? Where does the user get registered? Where can I see it? The OneSignal dashboard still shows a player id but no user id. What is the exact process by which I can use this action to associate a device with a user?

I would really prefer to be able to get the player id within the app. It seems like it should be returned by the Register action.

Figured it out. Future readers, create a client action with an output parameter and the following JavaScript:

window.plugins.OneSignal.getIds(function(ids) {
  $resolve();
  $parameters.yourOutputParameter = ids.userId;
});

This uses the OneSignal PhoneGap SDK as documented here

Solution

Hey, Mitchell,

Thanks for sharing! I'll pass on the feedback to the team about it, so they can weight if it should be included in the plugin (looks like it).

In the meantime, let me just point out that, according to the documentation, there's a chance that those values might be empty, so make sure you create your logic around it.

Thanks again, and best regards,

Carlos Simões

Solution

Have there been any updates on this? I am trying to get the player ID of my registered Device but the Javascript that Mitchell has provided does not seem to be executing on my device. I am trying to print the result in the logs or in an alert but it does not seem to be executing. 


Is there any reason the player_id of the registered Device is not available as an output parameter from the registration?


Update: I tried this without the Resolve() and I was able to get a response but it was null. Why would it be null?  Mitchell, were you able to successfully get the playerId? how so?

So it looks like there have been two new methods added. GetDeviceID and GetDeviceType.

Get DeviceID returns the "DeviceID" but this is not the same as the PlayerID, which is required for sending push notifications to an individual device. In fact, I cannot find this device ID anywhere in the all users of my OneSignal application. 

What is the "DeviceID" returned in the new method and how can it be mapped to the playerId?