get include_player_ids params values for POST request in Postman - android

I'm working on Remote Notifications in my Ionic App using OneSignal.
I have created an App in OneSignal, configured it for my app and initiated the service as per the Official Docs.
To test this, I am using Postman Chrome Extension. So, after adding the POST Request URL, where can I find the String values for the include_player_ids key.
I have my app still in testing state.
What's the code in typescript to get the value of include_player_ids from our Mobile Device?

Assuming you are using the OneSignal Native Android SDK, you should use the OneSignal idsAvailable method to get the device's OneSignal Player Id and then pass this value to your server.

window.plugins.OneSignal.getIds(function(ids) {
console.log('getIds: ' , ids);
self.deviceToken = ids.pushToken;
self.userId = ids.userId;
console.log(self.userId);
});
That gives u deviceToken and OneSignal User ID, which is referred to as Player ID
I copied the value from the console and used!
Thanks #Saiy2k

Related

FCM: Invalid registration token. Check the token format

I’m implementing Firebase Cloud Messaging (FCM) and am experiencing a problem that I’m unable to solve. I have implemented FirebaseMessagingService and FirebaseInstanceIdService according to the guide(s). When I go to Firebase Console for my app, and use the Notification function, I can successfully send a message to ALL my app instances (using the package name).
Now, in the code I have fetched the Firebase Instance Id (token) by use of the following code:
String token = FirebaseInstanceId.getInstance().getToken();
SendFirebaseTokenToServer(token);
(note that currently I’m using HTTP protocol, as my server does not yet have a cert). Anyway using the token I get from the call above, I go back to the Firebase Console and try to send a message to one (1) installed instance of my app. I grab the token from our server DB where it is stored as "varchar(max)". When I do that I get the following error message:
Invalid registration token. Check the token format.
I have googled that and found only one hit (having to do with Firebase and iOS):
http://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format
That issue indicates that a cert was required (I think I’m reading it correctly). I’m not sure what I’m doing wrong. I need to get this to work using the Firebase Console first, then my server guy can start on his end knowing that it should work.
Turns out i was programatically encoding all POST or PUT parameters prior to sending to our server. the FCM token had a semicolon in it, which got encoded to a "%3A", seemingly causing the problem.
do NOT encode the FCM token.

Get GCM registration id using HTTP in react native

I'm building a React Native app and want to include push notifications for Android. We currently have the infrastructure for GCM push from our last app. However this time I need to use the JS code to pass the registration id to our push servers. The old app was a native Java app and used:
gcm = GoogleCloudMessaging.getInstance(mActivityContext);
regid = getRegistrationId(mActivityContext);
I have the API key and sender Id but I need to get the regid using over HTTP not using the Java library used there. I have found https://android.googleapis.com/gcm/register but I can't find any docs on how to use it.
The implementation for this can be done in 2 ways:
Do a volley implementation in android code and pass the result you get to the Javascript through the JS bridge.U can pass it in a form of promise to the javascript.Please refer to the following link:
http://facebook.github.io/react-native/releases/next/docs/native-modules-android.html
Use fetch api.U can use body and headers in the fetch method.Please refer to the following link:
http://facebook.github.io/react-native/releases/next/docs/network.html#using-other-networking-libraries

How can i debug phone-gap PushPlugin?

I am using xmpp/css push implementation, all is fine at server side but I am not receiving any push on device.
So, i need to debug PhoneGap PushPlugin
Firstly please check whether device id is generated or not at Android App side by checking logs.
If generated, then-
Try to use DevHttpClient Google Chrome plugin.
In that, you need to enter
Request URL : android.googleapis.com/gcm/send
Content-Type : application/x-www-form-urlencoded
Authorization : key=API_KEY
And in body :
{
"registration_ids":["XXX Device ID XXX"],
"data":{"message":"Push Notification Test"}
}
You can check this image:

Could not get the apid in the client side/js

I m using Urbanairship with Phonegap. The push messaging is working fine in many cases but I m having problem capturing the "APID" in the client side.
The device is registered and APID is generated but when I try to call the registerEvent in the javascript, the push object is empty and the function is not called.
push = window.pushNotification; //this returns an object
push.registerEvent('registration', function (error, id) {//this is never fired
I m using PhoneGap 2.9
//in the config.xml
<plugin name="PushNotificationPlugin" value="com.urbanairship.phonegap.plugins.PushNotificationPlugin" onload="true"/>
If I copy the APID from the logcat(eclipse) and use it, the messaging is working. The only problem is I m not able to get the APID in my client side
Please help
You need to use Phonegap 3.0, as stated on the Github page, and if you look at the Example/index.html you can see that they get the push object using:
var push = window.plugins.pushNotification;
Then push.registerEvent('registration', callback) should work.

getting Google oauth authorization token from Android- return with invalid_scope/ Unknown error

I try to use Google oauth to authenticate users on my android app.
Then I would like to send it to my app server so it can connect at any time with Google calendar.
I tried to use
GoogleAuthUtil.getToken(getApplicationContext(), mAccountName, mScope);
Following this article:
https://developers.google.com/accounts/docs/CrossClientAuth
When I use it with scope
mScope = "oauth2:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
I get a token, which is valid for an hour
But when I try to get an authorization code (so I can get a refresh token that is valid for longer time, using
mScope2 ="oauth2:server:client_id:{CLIENT_ID}.apps.googleusercontent.com"+ ":api_scope:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
I receive either "invalid_scope" or "Unknown" exceptions.
What am I doing wrong?
EDIT:
OK, After creating a new app on google API console and adding plus.login to the scope I get a code, but for some reason my server can't resolve this token. When tying to resolve server gets an error about the redirection URL.
BTW, When I do the web flow with same parameters it works.
OK, found the solution, I expected Google to have a lot better documentation about working with Google Oauth and Android. A few things you have to know to work with Android and offline token
When you create google Client ID Don't create a service application before you create a web application
Must include https://www.googleapis.com/auth/plus.login in your scope
The weirdest, to resolve the one time authorization code on my server, I had to use the redirection URL from the Android client ID details (which doesn't even look like a url) and not from the Web client details on Google API console.
That scope string is only documented to work when passed to GoogleAuthUtil(), see http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html, on Android. But it would be cool if it worked on iOS too; our infrastructure there is a little behind where we’re at on Android.
I have had the same issue then i realised that my app is not published and is in debug mode, so i had to add test users to the Google project -> Consent Screen, then i was able to fetch the token for the added test user.
You just need to follow the correct steps/format for specifying the scopes. Find them here https://developers.google.com/android/guides/http-auth#SpecifyingScopes

Categories

Resources