I am trying to get Firebase dynamic links to work in my app.
I have a function with the following
//long
String link = "http://www.blessd.mobi";
DynamicLink m = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain("blessd.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("mobi.blessd")
.build())
.buildDynamicLink();
Uri t = m.getUri();
String ll = t.toString();
Log.d(TAG + " long link:", ll);
//short
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("http://www.blessd.mobi"))
.setDynamicLinkDomain("blessd.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("mobi.blessd")
.build())
.buildShortDynamicLink()
.addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
// Short link created
Uri shortLink = task.getResult().getShortLink();
Uri flowchartLink = task.getResult().getPreviewLink();
String sl = shortLink.toString();
String fcl = flowchartLink.toString();
Log.d(TAG + " short link:", sl);
Log.d(TAG + " flow chat link:", fcl);
} else {
// Error
// ...
Log.d(TAG + " short links:", "problem");
Exception exception = task.getException();
Log.e("TAG", "Short Dynamic link error", exception);
}
}
});
I successfully generate a long link. I have debugged the long link in debug mode in a web browser and there are no errors.
The short link however does not run and I receive the following error:
09-03 16:14:06.816 4551-4551/? E/TAG: Short Dynamic link error com.google.android.gms.common.api.ApiException: 8:
Thanks.
With Dynamic Links, your users get the best available experience for the platform they open your link on. If a user opens a Dynamic Link on iOS or Android, they can be taken directly to the linked content in your native app.
Dynamic Links are smart URLs that allow you to send existing and potential users to any location within your iOS or Android app. They survive the app install process, so even new users see the content they're looking for when they open the app for the first time. Dynamic Links are no-cost forever, for any scale.
The created short Dynamic Link will not expire. Repeated calls with the same long Dynamic Link or Dynamic Link information will produce the same short Dynamic Link. The Dynamic Link domain in the request must be owned by requester's Firebase project.
Use this setting to prevent your Dynamic Links URLs from being guessed and crawled, which can potentially expose sensitive information to unintended recipients. If you set the parameter to "SHORT", the path component will be a string that is only as long as needed to be unique, with a minimum length of 4 characters.
You can also create a short Dynamic Link by specifying the Dynamic Link parameters directly. To do so, make an HTTP POST request to the shortLinks endpoint, specifying the Dynamic Link parameters in the dynamicLinkInfo parameter. For example: For a complete specification of the dynamicLinkInfo object, see the API reference.
You can also set the suffix parameter to specify how the path component of the short Dynamic Link is generated. By default, or if you set the parameter to "UNGUESSABLE", the path component will be a 17-character string, such as in the following example: Such strings are created by base62-encoding randomly generated 96-bit numbers.
You can create short Dynamic Links with the Firebase Dynamic Links REST API. This API accepts either a long Dynamic Link or an object containing Dynamic Link parameters, and returns a URL like the following example:
Firebase team was able to reproduce the issue and has already reported this to their team.
Currently, there are two workarounds for this issue:
Use the Dynamic Link version 16.0.1 to be able to generate a short Dynamic Link:
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-dynamic-links:16.0.1'
Stick in using version 16.1.1, create a long link first then try to shorten the long Dynamic Link using this guide.
Use my solution to build your short link and avoid downgrading firebase.
String builtLink = new LinkBuilder().setDomain("example.page.link")
.setLink("your link goes here")
.setSd(socialTagDesc)
.setSt(socialTagTitle)
.setSi("social image link here")
.setApn("android app pkg")
.setAmv("android min version")
.setIbi("ios app pkg")
.setImv("ios app min version")
.setIsi("iosid number").build();
DynamicLink.Builder builder = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse(builtLink));
builder.buildShortDynamicLink()
.addOnSuccessListener(listener)
.addOnFailureListener(failureListener);
public class LinkBuilder
{
private String domain;
private String link;
private String apn;
private String amv;
private String ibi;
private String imv;
private String isi;
private String st;
private String sd;
private String si;
public String getURLEncode(String input){
try
{
return URLEncoder.encode(input, "UTF-8");
}
catch (Exception ex){
Timber.e(ex);
}
return input;
}
public LinkBuilder setDomain(String domain) {
this.domain = domain;
return this;
}
public LinkBuilder setLink(String link) {
this.link = getURLEncode(link);
return this;
}
public LinkBuilder setApn(String apn) {
this.apn = apn;
return this;
}
public LinkBuilder setAmv(String amv) {
this.amv = amv;
return this;
}
public LinkBuilder setIbi(String ibi) {
this.ibi = ibi;
return this;
}
public LinkBuilder setImv(String imv) {
this.imv = imv;
return this;
}
public LinkBuilder setIsi(String isi) {
this.isi = isi;
return this;
}
public LinkBuilder setSt(String st) {
this.st = getURLEncode(st);
return this;
}
public LinkBuilder setSd(String sd) {
this.sd = getURLEncode(sd);;
return this;
}
public LinkBuilder setSi(String si) {
this.si = getURLEncode(si);;
return this;
}
public String build(){
return String.format("https://%s/?link=%s&apn=%s&amv=%s&ibi=%s&imv=%s&isi=%s&st=%s&sd=%s&si=%s"
,domain, link, apn, amv, ibi, imv,isi,st,sd,si);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With