我在网站上提到了许多问题,但是使用Firebase动态链接生成短动态链接仍然没有麻烦。
我正在尝试从动态链接生成短动态链接。生成动态链接后,它可以完美地工作并可以与任何其他应用共享。但是无法从该动态链接生成短链接。
它在logcat中显示这样的错误:
com.google.android.gms.common.api.ApiException: 400: Cannot shorten a short Dynamic Link: https://onestickers.page.link/Stickers?sd=Stickers%20for%20WhatsApp%20-%20WAStickerApps&si=https%3A%2F%2Fonestickers.com%2Fimg%2Fmain-logo.png&st=One%20Stickers&amv=11&apn=stickersforwhatsapp.wastickerapps&link=https%3A%2F%2Fapi.wastickerapp.co%3Fpackid%3D201
我正在使用代码创建动态链接:
private void createShareUri(String pid) {
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("api.wastickerapp.co")
.appendQueryParameter("packid", pid);
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setDomainUriPrefix("https://onestickers.page.link/Stickers")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(11)
.build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle("One Stickers")
.setDescription("Stickers for WhatsApp - WAStickerApps")
.setImageUrl(Uri.parse("https://onestickers.com/img/main-logo.png"))
.build())
.setLink(builder.build())
.buildDynamicLink();
}
如果我将这个链接通过Intent发送到任何应用程序,它也可以正常工作!
但是在那之后,我试图生成短链接:
private void createShortDynamicLink(Uri uri) {
FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(uri)
.buildShortDynamicLink()
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
Uri shortLink = Objects.requireNonNull(task.getResult()).getShortLink();
//Uri flowchartLink = task.getResult().getPreviewLink();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Stickers Link");
intent.putExtra(Intent.EXTRA_TEXT, shortLink.toString());
startActivity(intent);
}
}).addOnFailureListener(mContext, e -> Log.e("DynamicLink>>>", Log.getStackTraceString(e)));
}
然后显示logcat!:
E/DynamicLink>>>: com.google.android.gms.common.api.ApiException: 400: Cannot shorten a short Dynamic Link: https://onestickers.page.link/Stickers?sd=Stickers%20for%20WhatsApp%20-%20WAStickerApps&si=https%3A%2F%2Fonestickers.com%2Fimg%2Fmain-logo.png&st=One%20Stickers&amv=11&apn=stickersforwhatsapp.wastickerapps&link=https%3A%2F%2Fapi.wastickerapp.co%3Fpackid%3D201 [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]
at com.google.android.gms.common.api.internal.TaskUtil.setResultOrApiException(Unknown Source:6)
at com.google.firebase.dynamiclinks.internal.zzi.zza(Unknown Source:4)
at com.google.firebase.dynamiclinks.internal.zzn.dispatchTransaction(Unknown Source:10)
at com.google.android.gms.internal.firebase_dynamic_links.zzb.onTransact(Unknown Source:12)
at android.os.Binder.execTransact(Binder.java:697)
如果Android中还有其他技术,请提出建议。
答案 0 :(得分:0)
在创建这样的长链接时也要创建短链接
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("api.wastickerapp.co")
.appendQueryParameter("packid", pid);
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(builder.build())
.setDomainUriPrefix("https://onestickers.page.link/Stickers")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(11)
.build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle("One Stickers")
.setDescription("Stickers for WhatsApp - WAStickerApps")
.setImageUrl(Uri.parse("https://onestickers.com/img/main-logo.png"))
.build())
.buildShortDynamicLink()
答案 1 :(得分:0)
尝试使用原始网址 https://app.page.link/ 而不是 https://app.page.link/ChosenName
在您的情况下,它将是: setDomainUriPrefix("https://onestickers.page.link/") 而不是 setDomainUriPrefix("https://onestickers.page.link/Stickers")