0

我正在尝试使用 Google Apps 脚本通过 API 创建 Firebase 动态链接。我们将它用作 shortLink 生成器(有点像这里的示例)。

当我通过 API 创建短链接时,我会收到带有生成的短链接地址的 JSON 响应。但是,当我尝试访问短链接时,我收到以下消息:

Invalid Dynamic Link - Blocked
Target url 'https://my.destination.com/aPobMsvkVUWEGjxisRNyfA2?fn=John&mn=J&ln=Doe&ci=Nowhere&st=IL&pc=12345-6789' is disallowed.
    
If you are the developer of this app, ensure that your Dynamic Links domain is correctly configured and that the path component of this URL is valid.

我已将 my.domain.com 添加为自定义域,并且在 Firebase 控制台的域白名单设置中允许使用 my.destination.com:

^https://my\.destination\.com/.*
^https://my.destination.com*

奇怪的是 - 我可以从 Firebase 控制台创建一个动态链接,使用相同的目标 URL,并且重定向有效!所以我怀疑问题不是实际的目标 URL,而是我构建或提交 API 请求的方式。以下是 Apps Script 中的相关代码:

    function myFunction() {
        
          var apiKey = "apikeyblahblahblah";

          var wholeLink = "https://my.destination.com/aPobMsvkVUWEGjxisRNyfA2?fn=John&mn=J&ln=Doe&ci=Nowhere&st=IL&pc=12345-6789";
          
          var payload = {
            "dynamicLinkInfo": {
              "domainUriPrefix": "https://my.domain.com",
              "link": wholeLink
            },
            "suffix": {
              "option": "UNGUESSABLE" 
            }
          };
        
          var options = {
            'method': 'POST',
            "contentType": "application/json",
            'payload': JSON.stringify(payload),
            muteHttpExceptions: true
          };
        
          var url = 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=' + apiKey;
        
          var response = UrlFetchApp.fetch(url, options);
          var json = response.getContentText();
          var data = JSON.parse(json);
          var obj = data["shortLink"];
          Logger.log(obj)

有没有人有任何建议让我尝试让它发挥作用?谢谢!

4

1 回答 1

0

不确定这是否是问题,但查看 firebase 控制台中的示例代码,您可能需要在白名单域末尾添加“$”符号。

^https://mybrand.com/.*$
^https://play.google.com/.*id=myapp.com$
^https://itunes.apple.com/.*id123$

于 2021-07-05T02:20:53.167 回答