0

I need to create a short link for URL like the following - howdoyoudo.co.il?id=123&evaluator=7

Using the following code I get a partial shortcut that link me to howdoyoudo.co.il?id=123

I tried set the pass the URL like this howdoyoudo.co.il?id=123%26evaluator=7 and still getting a shortcut with a partial URL.

Code follows -

String evaluationLink = "howdoyoudo.co.il?id=123%26evaluator=7";
String longLink = "https://k5xt4.app.goo.gl/?link=" + evaluationLink;

        Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLongLink(Uri.parse(longLink))
                .buildShortDynamicLink()
                .addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
                    @Override
                    public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                        if (task.isSuccessful()) {
                            Uri shortLink = task.getResult().getShortLink();
                            Uri flowchartLink =  task.getResult().getPreviewLink();
                            //Partial shortLink :(
                        } else {
                            // Error

                        }
                    }
                });

UPDATED CODE:

        Short i = 10; //for testing only

        String evaluationLink = "http://howdoyoudo.co.il?id=123";
        String longLink = "https://k5xt4.app.goo.gl/?link=" + evaluationLink + "&evaluatorID=" + Integer.toString(i);
        String encodedLink = null;
        try {
            encodedLink = URLEncoder.encode(longLink, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLongLink(Uri.parse(encodedLink))
                .buildShortDynamicLink()
                .addOnCompleteListener(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();

//                                

                        } else {
                            // Error
                            // ...
                        }
                    }
                });
Shai
  • 355
  • 2
  • 5
  • 18

2 Answers2

1

SOLVED:

First I encoded my link with the parameters like this -

String evaluationLink = "http://howdoyoudo.co.il?id=123&evaluatorID=10";
        String encodedLink = null;
        try {
            encodedLink = URLEncoder.encode(evaluationLink, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

than I set the string to be shorten like this -

String longLink = "https://k5xt4.app.goo.gl/?link=" + encodedLink;

Finally I made a call for shortening longLink with the following code -

Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLongLink(Uri.parse(longLink))
                .buildShortDynamicLink()
                .addOnCompleteListener(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();

                        } else {
                            // Error
                            // ...
                        }
                    }
                });
Shai
  • 355
  • 2
  • 5
  • 18
0

You're right about encoding to send a link with multiple parameters, but, you need to encode the full link, not just the part that's giving you issues.

Plus, the link should include the url scheme, i.e. http or https in this particular case:

String evaluationLink = "http://howdoyoudo.co.il?id=123&evaluator=7";

String encodedLink = URLEncoder.encode(evaluationLink, "UTF-8");

See: How get extra parameter from dynamic link using Firebase?

AarónBC.
  • 1,280
  • 9
  • 14