Dynamic not found when building link from app #6007
Unanswered
elinahovakimyan
asked this question in
Q&A
Replies: 1 comment
-
Hi there! The only way I'm aware of to generate a real fully-featured short dynamic link inside the mobile app is to do it with a cloud function that has access to the firebase-admin-sdk. This is how I do it, I'm just copy-splatting my cloud function in here, it requires some library features I am not including and is all customized for my work project as well as possibly being chatty in the logs and or buggy, so be careful, but it works for me when called from thhe app import * as functions from 'firebase-functions';
import * as rp from 'request-promise-native';
import { EventEmitter } from 'events';
import { processCorrelationIds, sendError, sendSuccess } from './lib';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const cors = require('cors')({ origin: true });
const api_key = functions.config().apikeys.dynamiclinks;
// Set up logging
// https://firebase.google.com/docs/functions/writing-and-viewing-logs
// https://us-central1-kscoreappdev.cloudfunctions.net/getPublicProfile
// http://localhost:5000/kscoreappdev/us-central1/getPublicProfile
export const getProfileLink = functions
.runWith({
memory: functions.VALID_MEMORY_OPTIONS[1], // 128MB was attempted and results in out of memory
})
.https.onRequest(async (req, res) => {
return cors(req, res, async () => {
processCorrelationIds(req, res);
if (!req.body.data || !req.body.data.longLink) {
throw new functions.https.HttpsError('internal', 'Missing link');
}
const longLink = req.body.data.longLink;
res.locals.longLink = longLink;
console.log(
'getProfileLink for ' + longLink + ' Correlation-ID: ' + res.locals.correlationId
);
console.log('Full inbound message: ' + JSON.stringify(req.body.data));
const options = {
method: 'POST',
uri: `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${api_key}`,
gzip: true,
json: true,
body: {
longDynamicLink: longLink,
suffix: {
option: 'SHORT',
},
},
};
let body;
try {
body = await rp(options);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
return sendError(res, e.error.error);
}
console.log('got link response: ' + JSON.stringify(body));
try {
EventEmitter.defaultMaxListeners = 200;
return sendSuccess(res, { result: body });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
console.log('getProfileLink failure', e);
return sendError(res, 'Unable to getProfileLink');
}
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I am trying to generate dynamic links from the app but when I try to open I either get redirected to web or I get error Dynamic link not found.
When creating the link manually from console I use the web URL in deep link URL field so that it redirects to web version of our website on desktop and to app when opening from mobile. However, I am not able to find a way to do that from app by using
buildLink
orbuildShortLink
methods. When I add web URL as link, the generated link is just redirecting to web instead of app, and when I add mobile.website.com which is the URL for dynamic links, it is giving error dynamic link not found.How can I specify deep link from app code and make the generated links work?
Beta Was this translation helpful? Give feedback.
All reactions