Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShortDynamicLink is not generating short link for dynamic links

creating a dynamic link

  DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse("http://shaharapp.in/"))
            .setDynamicLinkDomain("https://cuh8g.app.goo.gl/")
            // Open links with this app on Android
            .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
            // Open links with com.example.ios on iOS
            .buildDynamicLink();

     dynamicLinkUri = dynamicLink.getUri();

after this, i get a long dynamic link. passing this dynamicLinkUri to shortLinkTask

 Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(dynamicLinkUri)
            .buildShortDynamicLink();
    shortLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
        @Override
        public void onComplete(@NonNull Task<ShortDynamicLink> task) {
            if (task.isSuccessful()) {


                Uri shortLink = task.getResult().getShortLink();
                link_txt.setText(shortLink.toString());
            }
            else {

                ViewGroup container = (ViewGroup) findViewById(R.id.snackbar_layout);
                Snackbar.make(container, "error", Snackbar.LENGTH_SHORT).show();

            }
        }
    });

This task is not completing, after debugging I got this

com.google.android.gms.common.api.ApiException: 7: Bad Request class com.google.android.gms.common.api.ApiException

like image 905
sam Avatar asked Aug 20 '17 15:08

sam


2 Answers

What is the long link you are getting? I suggest trying long link and ensure the link works correctly.

Also, append &d=1 to long link. Such link will navigate to debug page with possible errors/warnings displayed.

Looking at your code, one possible reason for failure is format of the domain. See example https://firebase.google.com/docs/dynamic-links/android/create . Domain expected to be string containing only domain, without https scheme:

.setDynamicLinkDomain("abc123.app.goo.gl")
like image 109
Oleksiy Ivanov Avatar answered Nov 17 '22 17:11

Oleksiy Ivanov


Make sure your .setDynamicLinkDomain("https://abc123.app.goo.gl") contains "https://"

like image 21
akaMahesh Avatar answered Nov 17 '22 18:11

akaMahesh