Firebase Dynamic Link ShortUrl not working in Android

9k views Asked by At

I am unable to create ShortDynamicLink using the Android Firebase Invite SDK. I can create long DynamicLink fine but it keeps failing to create ShortDynamic link, always giving an error message of Bad Request. Here is the code:

private void sendInvite(String uid, final String displayName){

        String link = "https://appdomain.com/?invitedby=" + uid;



        com.google.android.gms.tasks.Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLink(Uri.parse(link))
                .setDynamicLinkDomain(Constants.DYNAMIC_LINK_DOMAIN)
                .buildShortDynamicLink()
                .addOnCompleteListener(mActivity, new OnCompleteListener<ShortDynamicLink>() {
                    @Override
                    public void onComplete(@NonNull com.google.android.gms.tasks.Task<ShortDynamicLink> task) {
                        if (task.isSuccessful()){
                            Uri shortLink = task.getResult().getShortLink();

                            // String referrerName = SettingsHelper.getHelper(mActivity).getDisplayName();
                            String subject = String.format("%s wants you to try Awesome App!", displayName);
                            String invitationLink = shortLink.toString();
                            String msg = "Enjoy and share your moments with Awesome App! Use my referrer link: "
                                    + invitationLink;
                            String msgHtml = String.format("<p>Start having fun with Awesome App's! Use my "
                                    + "<a href=\"%s\">referrer link</a>!</p>", invitationLink);

                            Intent intent = new Intent(Intent.ACTION_SENDTO);
                            intent.setData(Uri.parse("mailto:")); // only email apps should handle this
                            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                            intent.putExtra(Intent.EXTRA_TEXT, msg);
                            intent.putExtra(Intent.EXTRA_HTML_TEXT, msgHtml);
                            if (intent.resolveActivity(getPackageManager()) != null) {
                                startActivity(intent);
                            }
                        }else {
                            String errorMessage = task.getException().getMessage();
                            Log.d(TAG, "Error creating Dynamic link " + errorMessage);
                        }

                    }
                });

}

Firebase Dynamic link API is enabled on Google Console as shown in the screenshot below: enter image description here

I can create a short dynamic link from the console but I wanted to be able to create it programmatically from the client.I am using the mos current version of Android SDK version 11.22.1

2

There are 2 answers

2
Oleksiy Ivanov On BEST ANSWER

Couple ideas to check:

1) Ensure that Constants.DYNAMIC_LINK_DOMAIN matches domain in your Firebase project. Ensure that App, you are creating the link, is part of that Firebase project. Ensure App has up-to-date GoogleServices.plist (or json).

2) Please share your long link you are having issues to shorten. For long link append &d=1 to the end of the link, and navigate to such link in browser. Ensure there is no error on this debug page and no relevant warnings.

Feel free to open Firebase bug or email myself at oleksiyi at google.com if that did not helped.

1
Pablo A. Martínez On

I would suggest to first create the long link and then the sort link, two steps, like in the following question Can't create short Firebase dynamic link -> Dynamic link error 7: Forbidden