0

I have an Expo/React Native app and I'm trying to implement Firebase Dynamic Links so that I can connect two users. So, user A would provide a dynamic link to user B. If user B doesn't have the app already installed, the link would send the user to App Store or Google Play for it to be installed. Once the installation is completed, the app would open up and retrieve user A's ID. If user B already has the app installed, the dynamic link would simply open the app and retrieve user A's ID.

Here's my question: if I define a dynamic link through the Firebase console, can I add parameters to it in my app? In other words, simply use the dynamic link on the console and add user A's ID to it.

Or if I need to send parameters that will depend on the user, do I need to generate them through the REST API?

I'm currently trying the REST API but keep getting 401 error. I simply make a POST call with the following request object to the https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={MyWebAPIKey}. And here's my request object:

{
 "dynamicLinkInfo": {
    "domainUriPrefix": "https://dl.mydomain.com/link",
    "link": "https://dl.mydomain.com/link?id=12345",
    "androidInfo": {
    "androidPackageName": "com.my-domain.myapp"
 },
 "iosInfo": {
    "iosBundleId": "com.my-domain.myapp"
 }
}

My https://dl.mydomain.com is hosted by Firebase and is used only for dynamic linking purposes and when I go to the Dynamic Links console, it shows https://dl.mydomain.com/link as my URL prefix.

So, I'm trying to understand:

  1. If I'll simply add a user ID as a parameter, can I use the dynamic link I create through the console or do I need to generate a dynamic link programmatically -- in my case through the REST API?
  2. If I need to do it through the REST API, what am I doing wrong in my code?

PS: Interestingly, when I try the POST call to Shortlinks API using Postman, it actually works and gives me a shortlink. When I try the same thing in my Expo app, I get a 401 error.

Sam
  • 26,817
  • 58
  • 206
  • 383
  • Hi there! I maintain react-native-firebase, does this method not work for you? https://rnfirebase.io/reference/dynamic-links#buildShortLink - then on the other side - when receiving it possibly with the app already open so you have to resolve it yourself, this method I added a while back should serve https://rnfirebase.io/reference/dynamic-links#resolveLink - if that works I can make it an answer I Just want to confirm you've tried it – Mike Hardy Oct 24 '21 at 00:53
  • Is it compatible with Expo? – Sam Oct 24 '21 at 01:45
  • DId you ask without trying? It should be... – Mike Hardy Oct 24 '21 at 13:32
  • @MikeHardy All the instructions on the website are for a RN app created with RN CLI. If I were to stick with Expo, looks like I'll have to eject. I'm currently on the managed workflow and I've been resisting ejecting the app which is why I was going along with the REST API in the first place. Need to research how ejecting the app will affect my development at this point. Anyway, thank you for the suggestion. – Sam Oct 24 '21 at 19:33
  • I've been following this thread but as I mentioned I keep getting a 401 error. https://stackoverflow.com/questions/62415111/is-there-a-way-to-integrate-an-expo-app-with-firebase-dynamic-links-without-deta – Sam Oct 24 '21 at 19:35
  • I'm under the impression that with the Expo config plugins just added, you do not have to eject? – Mike Hardy Oct 24 '21 at 22:54
  • So, I ejected and now I have a bare workflow project with `android` and `ios` folders. I was able to follow the instructions for Android without any issues but iOS is a different ballgame. First, I'm on a PC and don't have XCode. Second, I can't see `ios/myprojectname.xcodeproj` or `ios/myprojectname.xcworkspace` file. Instead, there's a `ios\myprojectname.xcodeproj` folder. Maybe because I'm on `Expo 43.0.0`. Not sure if the structure is different in latest version. – Sam Oct 25 '21 at 05:17
  • Is there a way to configure this for iOS without XCode? – Sam Oct 25 '21 at 05:22
  • As mentioned, I do not believe you need to eject just to use the dynamic links APIs to create or resolve links. You will need to eject if you want to set up handlers etc (though the basic react-native Linking module also works for most use cases). I don't think it is practical to develop for iOS with Xcode, as a general rule, sorry to say. Though you may like https://github.com/kholia/OSX-KVM - I use Ubuntu on the metal and a bunch of those to run macOS, although I have macs as well. – Mike Hardy Oct 25 '21 at 14:35
  • I've already ejected and it's a one-way street. There are a few other features that I'll be implementing in the app that would not work in the managed workflow anyway. I also got a hold of a Mac and configured things using the standard (not manual) instructions here https://rnfirebase.io/. I tested it and it failed but I realize I can't test things in emulators. I'll keep you posted on how it's going. Thanks for sticking with me on this. – Sam Oct 26 '21 at 05:09
  • I was under the impression that with source control nothing is a one-way street, you may always revert ? But if it's a requirement, it's a requirement (for other features, as you mention). Some things actually do work in emulators - specifically android emulators *with play store* (so you can check install behavior etc) work great. iOS some things work, but app install obviously does not. – Mike Hardy Oct 26 '21 at 13:05

0 Answers0