我需要为以下网址创建一个短链接 - 的 howdoyoudo.co.il?id=123&evaluator=7
使用以下代码,我得到一个部分快捷方式,将我链接到howdoyoudo.co.il?id=123
我尝试设置传递这样的网址 howdoyoudo.co.il?id=123%26evaluator=7 并且仍然使用部分URL获取快捷方式。
代码如下 -
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
}
}
});
更新代码:
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
// ...
}
}
});
答案 0 :(得分:1)
<强>解决:强>
首先,我使用像这样的参数编码我的链接 -
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();
}
比我设置字符串缩短一样 -
String longLink = "https://k5xt4.app.goo.gl/?link=" + encodedLink;
最后,我用以下代码 -
呼吁缩短 longLinkTask<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
// ...
}
}
});
答案 1 :(得分:0)
您对编码发送包含多个参数的链接是正确的,但是,您需要对完整链接进行编码,而不仅仅是为您提供问题的部分。
另外,该链接应包括网址方案,即在这种特殊情况下为http或https:
String evaluationLink = "http://howdoyoudo.co.il?id=123&evaluator=7";
String encodedLink = URLEncoder.encode(evaluationLink, "UTF-8");
请参阅:How get extra parameter from dynamic link using Firebase?