Firebase Dynamic Link setLongLink 字符串问题
Firebase Dynamic Link setLongLink string issue
我需要为 URL 创建一个简短的 link,如下所示 -
howdoyoudo.co.il?id=123&evaluator=7
使用以下代码,我得到了 link 到 howdoyoudo.co.il?id=123
的部分快捷方式
我试过像这样设置 URL 的传递 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
// ...
}
}
});
关于发送带有多个参数的 link 的编码是正确的,但是,您需要编码完整的 link,而不仅仅是给您带来问题的部分。
此外,link 应包括 url 方案,即在这种特殊情况下为 http 或 https:
String evaluationLink = "http://howdoyoudo.co.il?id=123&evaluator=7";
String encodedLink = URLEncoder.encode(evaluationLink, "UTF-8");
参见:
已解决:
首先我用这样的参数对 link 进行了编码 -
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;
最后我用下面的代码调用了缩短 longLink -
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
// ...
}
}
});
我需要为 URL 创建一个简短的 link,如下所示 - howdoyoudo.co.il?id=123&evaluator=7
使用以下代码,我得到了 link 到 howdoyoudo.co.il?id=123
的部分快捷方式我试过像这样设置 URL 的传递 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
// ...
}
}
});
关于发送带有多个参数的 link 的编码是正确的,但是,您需要编码完整的 link,而不仅仅是给您带来问题的部分。
此外,link 应包括 url 方案,即在这种特殊情况下为 http 或 https:
String evaluationLink = "http://howdoyoudo.co.il?id=123&evaluator=7";
String encodedLink = URLEncoder.encode(evaluationLink, "UTF-8");
参见:
已解决:
首先我用这样的参数对 link 进行了编码 -
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;
最后我用下面的代码调用了缩短 longLink -
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
// ...
}
}
});