olucurious / PyFCM

Python client for FCM - Firebase Cloud Messaging (Android, iOS and Web)
http://olucurious.github.io/PyFCM/
MIT License
802 stars 204 forks source link

How to get registration_id #305

Closed mahiuddin-dev closed 2 months ago

BetterAutomations commented 2 years ago

I had to get it within my Ionic/Angular/Capacitor app and send to my web API. Here's the relevant code:

import { HttpClient, HttpParams } from '@angular/common/http';
import {
  ActionPerformed,
  PushNotifications,
  PushNotificationSchema,
  Token,
} from '@capacitor/push-notifications';

PushNotifications.addListener('registration', (token: Token) => {
      console.debug('notifications token: ', JSON.stringify(token.value));
      if (!token) {
        throw new Error('Token empty');
      }
      this.saveToken(token);
}

private saveToken(token: Token): void {
    const params = new HttpParams().set(
      'value',
      btoa(JSON.stringify(token.value))
    );
    // I should change this to an httpClient.post(), .get() does work but it's not as clear what's happening
    this.httpClient.get('notification_tokens', { params })
LazzaAU commented 1 year ago

i've researched a HUGE amount of sites in regards to how to get the registration token using python. I can't for the life of me find out how to do it. Have i missed that vital part in the documentation or something ?

anyone got some tips please on how to get the token using python / kivy please ? in simple terms would be appreciated as ive already spent 12 hours researching it and my brain is going mushy hahah , cheers