expo: expo-notifications failing to get token

Summary

I am having issues with expo-notifications.

So I created a blank project with the expo init command, created a managed workflow, and installed expo notifications via expo install.

Then I copied the registerForPushNotificationsAsync from here, used it in a useEffect hook and got the following error: [Unhandled promise rejection: Error: Fetching the token failed: java.util.concurrent.ExecutionException: java.io.IOException: AUTHENTICATION_FAILED]

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

45

Environment

expo-env-info 1.0.5 environment info: System: OS: Windows 10 10.0.22000 Binaries: Node: 16.16.0 - C:\Program Files\nodejs\node.EXE npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD npmPackages: expo: ~45.0.0 => 45.0.6 react: 17.0.2 => 17.0.2 react-dom: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-web: 0.17.7 => 0.17.7 Expo Workflow: managed

Reproducible demo

https://docs.expo.dev/versions/latest/sdk/notifications/#api

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 16
  • Comments: 91 (8 by maintainers)

Most upvoted comments

I found a workaround for this issue. If the problem is that expo-notifications can’t find the projectID, just supply it:

const appConfig = require('../app.json');
const projectId = appConfig?.expo?.extra?.eas?.projectId;
const token = (await Notifications.getExpoPushTokenAsync({
	projectId
})).data;

This is working for me, and will enable me to keep developing and testing my notifications code, although I don’t feel like it should be necessary for production code, and I’m hoping that a proper fix is on the way.

I still keep getting this problem. asap update pleeeese

same here with slightly different error message_

Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.

Note: If we push to prodution then everything works. this is only an issue in expo go

Hi, I had same issue with No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself. when using EAS with developmentClient. When using Expo GO or standalone build with AES(“distribution”: “internal”) everything works OK.

To get it working I did add parameter experienceId, like: const token = (await Notifications.getExpoPushTokenAsync({experienceId: "@username/projectSlug"})).data; as mentioned at the docs https://docs.expo.dev/versions/latest/sdk/notifications/#getexpopushtokenasyncoptions-expotokenoptions-expopushtoken

experienceId (string) -- Although this is optional, we recommend explicitly passing it in. The ID of the experience to which the token should be attributed. Defaults to [Constants.manifest.id](https://docs.expo.dev/versions/latest/sdk/constants/#constantsmanifest) exposed by expo-constants. When building with EAS Build, or in the bare workflow, this is required and you must provide a value which takes the shape @username/projectSlug, where username is the Expo account that the project is associated with, and projectSlug is your [slug from app.json](https://docs.expo.dev/versions/latest/config/app/#slug).

I have checked that in EAS build with developmentClient Constants.manifest.id is undefined

Solution by @TheRealMikeD works also👍

I found a workaround for this issue. If the problem is that expo-notifications can’t find the projectID, just supply it:

const appConfig = require('../app.json');
const projectId = appConfig?.expo?.extra?.eas?.projectId;
const token = (await Notifications.getExpoPushTokenAsync({
	projectId
})).data;

This is working for me, and will enable me to keep developing and testing my notifications code, although I don’t feel like it should be necessary for production code, and I’m hoping that a proper fix is on the way.

Thank you! For Expo SDK 47 and up:

import Constants from 'expo-constants';

const projectId = Constants.expoConfig.extra.eas.projectId;

I am running into the exact same problem. Running on a development build on my iPhone on SDK 46. Getting a 401 when calling getExpoPushTokenAsync

Looks like patch is on the way!

https://github.com/expo/expo/pull/18652

I can confirm this is fixed in expo go 2.25.2 - which is already in the play store. Thanks a lot!

I still keep running into this error in production. Am I alone? I tried a bunch of things that people suggested around here, but nothing seems to do the trick. More specifically, I keep getting Error: Fetching token failed: java.io.IOException: FIS_AUTH_ERROR when calling getExpoPushTokenAsync.

const token = (await Notifications.getExpoPushTokenAsync({experienceId: "@username/projectSlug"})).data;

Please somebody gives this man a beer

Running into the same issue on expo go app in dev mode on android. I am using managed workflow. Expo go app version: 2.25.2

error notification Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.

code:

token = (await Notifications.getExpoPushTokenAsync()).data; 
console.log(token); 

Edit: Running eas init fixed it. It added a projectId to app.json and now Notifications.getExpoPushTokenAsync() works Thanks @usmangurowa

So I spent the whole of last night trying to fix this issue, I almost gave up when I saw the Expo Team comments. Hopefully this afternoon (it’s afternoon over here). I run eas init and this seems to fix the issue. I think the problem was because there is no projectId in the app.json file, running eas init will fetch the ID from your expo app hosted on the expo.dev site and add it to your app.json. Now I can get the push tokens.

Yes the problem is with expo go version=>2.25 And the solution is

  1. Probably short and recommended by other (not tested by me) => Downgrade to Expo 2.24.6 if you can
  2. If you have usb cable and you can attach device to dev computer then get rid of expo at all 2.1 use command “expo eject” => Go to react-native project 2.2 build again with command “npx react-native run-android” 2.3 Run “npx react-native start”

Everything works fine on Expo Go app now, but I still get the error [Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.] after building a dev client with eas build --profile development --platform android.

Anyone else experiencing the issue with development builds? Works fine on preview and production builds

No it does not work in dev right now. It used to work in older versions. But as described above: it still works in production app.

I think for me it doesn’t work even in production (I tried using an eas build yesterday).

Everything works fine on Expo Go app now, but I still get the error [Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.] after building a dev client with eas build --profile development --platform android. Anyone else experiencing the issue with development builds?

I also experience this even though I have updated expo-dev-client to 1.2.1

Yep. Same problem. The latest expo go from the app store works, but dev clients built with run:android / run:ios do not appear to. I’m guessing an update isn’t pushed out for the dev client code / generation that was required in expo go.

Expo Go

Version 2.24.6 is working fine. You’ll need to downgrade…

And in case anyone else runs into this — even though I had the same Google API key and google-services.json for dev and production, the API key was restricted to only the package fingerprint of the Expo-built Google Play-released version of the package. I had to extract the key of the development build by downloading the APK from the expo.dev builds page and running keytool -printcert -jarfile application.apk | grep SHA1 and then adding that to the API key restrictions. I’m not sure how long it took to update because getExpoPushTokenAsync() didn’t work at the end of the day but started working the next morning.

CleanShot 2023-08-03 at 08 36 40

Rotated our google-services.json creds and PNs are now working again. Not clear to me if this is a Google issue or an Expo issue.

Anyways I suspect that this issue is full of lots of people with different root issues that surface similarly.

Running into the same issue on expo go app in dev mode on android. I am using managed workflow. Expo go app version: 2.25.2

error notification Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.

code:

token = (await Notifications.getExpoPushTokenAsync()).data; 
console.log(token); 

Edit: Running eas init fixed it. It added a projectId to app.json and now Notifications.getExpoPushTokenAsync() works Thanks @usmangurowa

This worked perfectly 👍

Everything works fine on Expo Go app now, but I still get the error [Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.] after building a dev client with eas build --profile development --platform android. Anyone else experiencing the issue with development builds?

I also experience this even though I have updated expo-dev-client to 1.2.1

Yep. Same problem. The latest expo go from the app store works, but dev clients built with run:android / run:ios do not appear to. I’m guessing an update isn’t pushed out for the dev client code / generation that was required in expo go.

Same problem for me when running eas build --profile development

Aaaand 17 minutes after I posted that, I realized our error: We used a different API key for development than for production, and the API key I had didn’t match the one in google-services.json. Works for us now.

This is happening for us, too. We didn’t change a thing about our configuration and Android simply stopped being able to get a token. getDevicePushTokenAsync() fails with Error: Fetching the token failed: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERROR.

I’ve double checked all of our service accounts, API keys, google-services.json files, expo.dev settings, and everything matches up. My suspicion is that keys somewhere in Google’s system tend to expire, and I wonder if I redo everything if I’ll be able to get it all working again.

This is not something I want to do late at night when I get paged because our users aren’t getting notifications.

Everything works fine on Expo Go app now, but I still get the error [Error: No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.] after building a dev client with eas build --profile development --platform android. Anyone else experiencing the issue with development builds?

I also experience this even though I have updated expo-dev-client to 1.2.1

Same error - downgrading to 2.24_6_free (link above) worked fine. Alternatively where is it looking for the firebase project ID? And could this be manually set as a temporary workaround?

@boyarzun any suggestions on where to find that exact binary? Google Play only allows to download the latest version.

This is the first thing that came up: https://m.apkshub.com/down/host.exp.exponent_2.24.6_free

The link works, and downgrading does indeed solve the issue. Thanks!

I think this problem might be in expo go. After the new update, I am facing this problem. I try to install the expo-notifications older version, but the same problem occurred in the expo go. But after building it by expo build:android it works fine on apk.

@Tasluf665 yes you are right, the problem in the update of expo go, when I downgrade to Expo 2.24.6 everything is working fine and there is no issues with notifications, I got device push token registered successfully @brentvatne

I installed this version of Expo Go on my cell phone and now I can get the token without error.

@claudionhangapc I have downloaded the 2.23.2 version of Expo Go for android. And it worked.

I think this problem might be in expo go. After the new update, I am facing this problem. I try to install the expo-notifications older version, but the same problem occurred in the expo go. But after building it by expo build:android it works fine on apk.

@Tasluf665 yes you are right, the problem in the update of expo go, when I downgrade to Expo 2.24.6 everything is working fine and there is no issues with notifications, I got device push token registered successfully

@brentvatne

I think this problem might be in expo go. After the new update, I am facing this problem. I try to install the expo-notifications older version, but the same problem occurred in the expo go. But after building it by expo build:android it works fine on apk.

I am getting this error as well on Expo 46 with expo-ci 6.0.2 Error: Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.] Everything was working fine with Expo SDK 44 and expo-notifications (which was configured with the FCM project and includes the google-services.json per the Expo docs), then I upgraded to 46 and get that error with testing in the Expo Go app that uninstalled/reinstalled to have a clean slate to work with.