尝试使用 Branch SDK Flutter 自定义别名时生成短链接时出错

问题描述 投票:0回答:2

我想在我的 flutter 应用程序中实现一个共享功能,允许用户共享帖子,并且每个帖子都应该有一个唯一的链接,当我尝试自定义链接别名时,由于帖子 id: alias: 'https://wowclinic .app.link/offers/$offerId', //定义链接url, 我收到这个错误: I/BranchSDK(22688):服务器返回:[30e871a8ca2c41769294515af1169f7b-2023061409]状态:[400];数据:{“error”:{“code”:400,“message”:“提供的别名无效”}} I/flutter (22688):创建 URL 时遇到问题。无法使用该别名创建 URL。如果您想重用别名,请确保为所有参数提交相同的属性,并且用户是同一所有者。

  void initDeepLinkData() {
    metadata = BranchContentMetaData()
      ..addCustomMetadata('Key', 'share')
      ..addCustomMetadata('Offer_Id', offerId.toString())
      ..addCustomMetadata('Description', desc)

    buo = BranchUniversalObject(
        canonicalIdentifier: '/$offerId',

    //parameter canonicalUrl
        //If your content lives both on the web and in the app, make sure you set its canonical URL
        // (i.e. the URL of this piece of content on the web) when building any BUO.
        // By doing so, we’ll attribute clicks on the links that you generate back to their original web page,
        // even if the user goes to the app instead of your website! This will help your SEO efforts.
        canonicalUrl: 'https://www.wowclinic.net',
        title: 'Wow Clinic',
        imageUrl: imageURL,
        contentDescription: desc,

        contentMetadata: metadata,
        keywords: ['Plugin', 'Branch', 'Flutter'],
        publiclyIndex: true,
       locallyIndex: true,
        expirationDateInMilliSec: DateTime.now()
            .add(const Duration(days: 365))
            .millisecondsSinceEpoch);

    lp = BranchLinkProperties(
        channel: 'facebook',
        feature: 'sharing',
        //parameter alias
        //Instead of our standard encoded short url, you can specify the vanity alias.
        //For example, instead of a random string of characters/integers, you can set the vanity alias as *.app.link/devonaustin.
        //Aliases are enforced to be unique** and immutable per domain, and per link - they cannot be reused unless deleted.
        alias: 'https://wowclinic.app.link/offers/$offerId', //define link url,
        stage: 'new share',
        campaign: 'offer_share_campaign',
        tags: ['one', 'two', 'three'])

      ..addControlParam('\$ios_url', '/offers/$offerId')
      ..addControlParam('\$android_url', '/offers/$offerId')
      ..addControlParam('\$uri_redirect_mode', '1')
      ..addControlParam('\$ios_nativelink', true)
      ..addControlParam('\$match_duration', 7200)
      ..addControlParam('\$always_deeplink', true)
      ..addControlParam('\$android_redirect_timeout', 750)
      ..addControlParam('referring_user_id', 'user_id');

    eventStandard = BranchEvent.standardEvent(BranchStandardEvent.SHARE)

  }

  void generateLink(BuildContext context) async {
    BranchResponse response =
    await FlutterBranchSdk.getShortUrl(buo: buo!, linkProperties: lp);
    if (response.success) {
      url = response.result;
      Share.share(url);
      // showGeneratedLink(context, response.result);
    } else {
      print(response.errorMessage);
      GblFn.showSnackbar(
          ' Error:', 'Error : ${response.errorCode} - ${response.errorMessage}');
    }
  }

flutter deep-linking branch.io
2个回答
0
投票

这里的错误是预料之中的,因为您在别名字段中传递了完整的 URL 值 -

alias: 'https://wowclinic.app.link/offers/$offerId', //define link url,

除此之外,您可以将别名声明为

alias: 'offers/$offerId', //define link url,


0
投票

您好,您找到该错误的解决方案了吗?

© www.soinside.com 2019 - 2024. All rights reserved.