【问题标题】:firebase "long link is not parsable"firebase“长链接不可解析”
【发布时间】:2018-06-11 12:16:46
【问题描述】:

我想用 firebase 和 REST API 缩短 longLink,但我得到以下响应,但我不知道出了什么问题:

回复:

   {
        "error": {
            "code": 400,
            "message": "Long link is not parsable: https://www.google.de [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]",
            "status": "INVALID_ARGUMENT"
        }
    }

这就是我的做法:

请求:https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=(hereismyapikey)

身体看起来像这样:

{
   "longDynamicLink": "https://www.google.de",
   "suffix": {
    "option": "SHORT"
  }
}

我首先尝试使用我想要缩短的真实网址。同样的错误。比使用 google 和使用和不使用 http(s)。我没有选择,希望有人看到我在这里做错了什么。

编辑:完整的邮递员请求:

    "item": [
            {
                "name": "shortLinks",
                "request": {
                    "method": "POST",
                    "header": [
                        {
                            "key": "Content-Type",
                            "value": "application/json"
                        }
                    ],
                    "body": {
                        "mode": "raw",
                        "raw": "{\r\n   \"longDynamicLink\": \"www.google.de\",\r\n   \"suffix\": {\r\n    \"option\": \"SHORT\"\r\n  }\r\n}"
                    },
                    "url": {
                        "raw": "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=xxx",
                        "protocol": "https",
                        "host": [
                            "firebasedynamiclinks",
                            "googleapis",
                            "com"
                        ],
                        "path": [
                            "v1",
                            "shortLinks"
                        ],
                        "query": [
                            {
                                "key": "key",
                                "value": "xxx"
                            }
                        ]
                    }
                },
                "response": []
        }
    ]

【问题讨论】:

  • 显示完整的请求,即 curl 请求或邮递员请求。隐藏您的 api 密钥
  • @UmarHussain II 添加了它

标签: javascript rest firebase firebase-dynamic-links


【解决方案1】:

您使用的是创建动态链接的简单方法,大致相当于手动创建动态链接:https://firebase.google.com/docs/dynamic-links/create-manually

在文档中,如果您仔细查看示例中传递的链接,您将看到如下模式:

https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]

所以你应该根据这个格式化输入链接或使用在json中有很好的参数分解的参数创建:

https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters

这里是从参数创建firebase动态链接的api参考:

https://firebase.google.com/docs/reference/dynamic-links/link-shortener#parameters

【讨论】:

  • 谢谢。我忘记在我的域前面添加 Firebase 动态链接域...
【解决方案2】:

我发现JSON参数方法更容易。

var body = {
  "dynamicLinkInfo": {
    "dynamicLinkDomain": "yourcustom.page.link",
    "link": fileUrl
  },
  "suffix": {
    "option": "SHORT"
  }
};

那么,如果您使用的是 Node.js。 node-fetch 包 REST 调用的工作方式如下:

  var fetchFileUrl = fetch(YOUR_SHORTLINK_URL, { 
      method: 'POST',
      body: JSON.stringify(body),
      headers: { 'Content-Type': 'application/json' },
  }).then(function(response){
    return response.json();
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 2015-01-08
    相关资源
    最近更新 更多