动态链接短错误com.google.android.gms.common.api.ApiException:8:

时间:2018-09-03 14:55:39

标签: android firebase firebase-dynamic-links

我正在尝试使Firebase动态链接在我的应用中正常工作。

我具有以下功能

    //long
    String link = "http://www.blessd.mobi";
    DynamicLink m = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse(link))
            .setDynamicLinkDomain("blessd.page.link")
            .setAndroidParameters(
                    new DynamicLink.AndroidParameters.Builder("mobi.blessd")
                            .build())
            .buildDynamicLink();
    Uri t = m.getUri();
    String ll = t.toString();
    Log.d(TAG + " long link:", ll);

    //short
    Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse("http://www.blessd.mobi"))
            .setDynamicLinkDomain("blessd.page.link")
            .setAndroidParameters(
                    new DynamicLink.AndroidParameters.Builder("mobi.blessd")
                            .build())
            .buildShortDynamicLink()
            .addOnCompleteListener(this, 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();
                        String sl = shortLink.toString();
                        String fcl = flowchartLink.toString();
                        Log.d(TAG + " short link:", sl);
                        Log.d(TAG + " flow chat link:", fcl);
                    } else {
                        // Error
                        // ...
                        Log.d(TAG + " short links:", "problem");
                        Exception exception = task.getException();
                        Log.e("TAG", "Short Dynamic link error", exception);
                    }
                }
            });

我成功生成了一个长链接。我已经在网络浏览器中以调试模式调试了长链接, 没有错误。

enter image description here

但是短链接无法运行,并且我收到以下错误消息:

  

09-03 16:14:06.816 4551-4551 /? E / TAG:短动态链接错误       com.google.android.gms.common.api.ApiException:8:

谢谢。

3 个答案:

答案 0 :(得分:15)

Firebase团队能够重现此问题,并且已经将此问题报告给了他们的团队。

当前,此问题有两种解决方法:

  • 使用动态链接版本 16.0.1 可以生成简短的动态链接: implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-dynamic-links:16.0.1'

  • 使用版本 16.1.1 进行标记,首先创建一个长链接,然后尝试使用此guide来缩短长动态链接。

答案 1 :(得分:3)

使用我的解决方案来建立您的短链接,并避免降级Firebase。

           String builtLink = new LinkBuilder().setDomain("example.page.link")
           .setLink("your link goes here")
           .setSd(socialTagDesc)
           .setSt(socialTagTitle)
           .setSi("social image link here")
           .setApn("android app pkg")
           .setAmv("android min version")
           .setIbi("ios app pkg")
           .setImv("ios app min version")
           .setIsi("iosid number").build();

    DynamicLink.Builder builder =  FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(Uri.parse(builtLink));

    builder.buildShortDynamicLink()
            .addOnSuccessListener(listener)
            .addOnFailureListener(failureListener);





 public class LinkBuilder
 {
    private String domain;
    private String link;
    private String apn;
    private String amv;

    private String ibi;
    private String imv;
    private String isi;


    private String st;
    private String sd;
    private String si;

    public String getURLEncode(String input){

        try
        {
            return URLEncoder.encode(input, "UTF-8");
        }
        catch (Exception ex){
            Timber.e(ex);
        }

        return input;
    }


    public LinkBuilder setDomain(String domain) {
        this.domain = domain;
        return this;
    }

    public LinkBuilder setLink(String link) {
        this.link = getURLEncode(link);
        return this;
    }

    public LinkBuilder setApn(String apn) {
        this.apn = apn;
        return this;
    }

    public LinkBuilder setAmv(String amv) {
        this.amv = amv;
        return this;
    }

    public LinkBuilder setIbi(String ibi) {
        this.ibi = ibi;
        return this;
    }

    public LinkBuilder setImv(String imv) {
        this.imv = imv;
        return this;
    }

    public LinkBuilder setIsi(String isi) {
        this.isi = isi;
        return this;
    }

    public LinkBuilder setSt(String st) {
        this.st = getURLEncode(st);
        return this;
    }

    public LinkBuilder setSd(String sd) {
        this.sd = getURLEncode(sd);;
        return this;
    }

    public LinkBuilder setSi(String si) {
        this.si = getURLEncode(si);;
        return this;
    }

    public String build(){
        return String.format("https://%s/?link=%s&apn=%s&amv=%s&ibi=%s&imv=%s&isi=%s&st=%s&sd=%s&si=%s"
                ,domain, link, apn, amv, ibi, imv,isi,st,sd,si);
    }
}

答案 2 :(得分:0)

解决方案:

第1步:检查更新版本implementation 'com.google.android.gms:play-services-auth:18.1.0'

第2步:检查链接,domainUriPrefix应用程序级别和Firebase控制台动态链接设置

第3步:检查sha1键