例外:超过限制:urlfetch URL长度

发布于 2025-02-05 11:45:32 字数 751 浏览 1 评论 0原文

我正在从API中提取数据,不幸的是,该数据的URL/端点很大。 是否有任何方法可以缩短URL以绕过例外:超过限制:urlfetch URL长度误差?

我发现了这一点: https://github.com/github.com/amitwilson/amitwilson/googleappsscript/blob/master/ LinkShortner ,但我不知道如何正确使用它,因为我进行的大多数API调用都是动态生成的。

这是一个示例链接(“ Cursor =”之后的字母是一个光标键,每次都不同):

https://api.x.immutable.com/v1/orders?include_fees = false=false&status; status; status = fill& buy_token_address = 0xacb3c6a43d15b907e8433077b6d38AeAe40936fe2c& orde_by = updated_timestamp&amp&amp&amp&amp = desc& use = desc& use = 0x72a2ffa8be361d4aa am am ; page_size = 200& cursor = _

I am pulling data from an API which unfortunately has very big urls/end points.
Is there any way to shorten urls in order to bypass the Exception: Limit Exceeded: URLFetch URL Length error?

I found this: https://github.com/amitwilson/GoogleAppsScript/blob/master/LinkShortner but I don't know how to use it properly since most of the api calls i make are generated dynamically.

This is an example link (letters after "cursor=" is a cursor key which is different every time):

https://api.x.immutable.com/v1/orders?include_fees=false&status=filled&buy_token_address=0xacb3c6a43d15b907e8433077b6d38ae40936fe2c&order_by=updated_timestamp&direction=desc&user=0x72a2ffa8be361d4a5d575c55b7382d8c6317f77d&page_size=200&cursor=eyJvcmRlcl9pZCI6MTk0NTk2NzUyLCJzZXFfbnVtIjowLCJzdGF0dXMiOiJmaWxsZWQiLCJzdGFya19rZXkiOiIweDA3MWU2NjU0NTMzMGJiOGY5NDQ4ZWU1YTM3YTI5ODViZGYzYjQ1NzYwNDA5ODE4YmEwYTY0NmUxNjU4NTdhMWIiLCJ2YXVsdF9pZCI6MCwiZXRoZXJfa2V5IjoiMHg3MmEyZmZhOGJlMzYxZDRhNWQ1NzVjNTViNzM4MmQ4YzYzMTdmNzdkIiwic2VsbF90b2tlbl90eXBlIjoiRVRIIiwic2VsbF90b2tlbl9pZCI6IiIsInNlbGxfY2xpZW50X3Rva2VuX2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wWiIsImNyZWF0ZWRfYXQiOiIyMDIyLTA1LTAzVDEwOjIwOjM0Ljc4ODkxN1oiLCJ1cGRhdGVkX2F0IjoiMjAyMi0wNS0wM1QxMDoyMDozNC43ODg5MTdaIiwiRmVlcyI6Ilczc2lZVzF2ZFc1MElqb2dJakk0TkRNd01EQXdNREF3TURBd0lpd2dJbVpsWlY5MGVYQmxJam9nSW0xaGEyVnlJaXdnSW05eVpHVnlYMmxrSWpvZ01UazBOVGsyTnpVeUxDQWljbVZqYVhCcFpXNTBYMlYwYUdWeVgydGxlU0k2SUNJd2VEVmpNell6WVRKaFlUZzJPV1F3WXpVeU1XTm1ZVE5sWWpCbE16YzBPVEpqTUdWaU5UbGxOVGdpTENBaWNtVmphWEJwWlc1MFgzTjBZWEpyWDJ0bGVTSTZJQ0l3ZURBMk1UY3haVEpoWlRRMU5qTXlNVE15TWpaak5XWm1aV1JpT1RSaE9UVXlOV0ppWm1Zell6bGtZMkpoWm1KaFpURTVabUk0TjJOa1ltSXpOMk5sTVdVaWZWMD0ifQ

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初雪 2025-02-12 11:45:33

例如,在您的情况下,以下示例脚本怎么样?

示例脚本:

在使用此脚本之前,请设置apikeyyourdynamiclinkdomain。您的yourdynamicLinkDomain可能就像https://##.page.link

const apiKey = "###"; // Please set your API key.
const yourDynamicLinkDomain = "###"; // Please set your dynamic link domain.

function getShortUrl_(longUrl) {

  const url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + apiKey;
  const options = {
    payload: JSON.stringify({
      dynamicLinkInfo: {
        dynamicLinkDomain: yourDynamicLinkDomain,
        link: longUrl,
      },
    }),
    contentType: "application/json",
  };
  const res = UrlFetchApp.fetch(url, options);
  const { shortLink } = JSON.parse(res.getContentText());
  return shortLink;
}

// Please run this function.
function main() {

  // do something for retrieving the long URL in your actual script.
  const longUrl = "###"; // It supposes that your long URL is put to longUrl.

  const shortUrl = getShortUrl_(longUrl); // Here, the long URL is shortned. You can use this.

  // If "options" is required to be used, please use this.
  const options = {

  };
  const res = UrlFetchApp.fetch(shortUrl, options);

}
  • 在此示例脚本中,它假设通过您当前的脚本,longurl。并且,此示例脚本从长URL转换为短URL,并使用功能getShorturl _将其转换为短URL。而且,您可以使用urlfetchapp使用此简短的URL。

注意:

  • 此示例脚本假设您已经能够使用Firebase Dynamic Links API。请小心。

    • 如果您从未能够使用Firebase Dynamic Links API,请检查官方文件。而且,以下流程可能很有用。
      请检查以下流程。

      1. 请创建一个新的Firebase项目,并将其链接到您的Google Cloud Platform Project。 ref
        • 目前,请在“动态链接”中设置dynamiclinkdomain
      2. 请在API控制台上启用Firebase Dynamic Links API。
      3. 请从您的Google Cloud Platform Project创建您的API密钥。
        • 请在上面的脚本中使用此API。
  • 当我测试此脚本时,我可以确认将长URL转换为短URL,并且可以与urlfetchapp一起使用短URL。

  • 如果我误解了,但是我不知道如何正确使用它,因为我进行的大多数API调用都是动态生成的。,请告诉我。

参考:

添加:

从您的以下答复中,

嘿,我制作了一个示例表,这样您就可以看到我如何在202行中以黄色突出显示Longurl。 docs.google.com/spreadsheets/d/其他API工作如下:它可以拉出200行,然后在每个呼叫的最后一行中显示此光标ID,必须在下一行中再次调用,以显示下一个光标200行。

检查我以前的答复中的示例表。 Longurl以黄色突出显示。

当我看到您的样本电子表格时,似乎您正在使用长URL作为= importjson(ConcateNate(“ https://api.x.immutable.com/v1/orders?include_fees = fees = fees = false&Amp; Status = status = falledus = fillid& amp; buy_token_address = 0xacb3c6a43d15b907e8433077b6d38AeAe40936fe2c& amp; amp; orde_by = updated_timestamp&amp&amp&amp&amp = desc& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp》 = 200& cursor =“,w202),”,“ notruncate,Nohewers”)。但是不幸的是,从您的问题和您的答复来看,我没注意到您正在这样使用。

在这种情况下,需要通过如下修改我的示例脚本。

示例脚本:

请将以下脚本复制到电子表格的脚本编辑器并保存脚本。

function getShortUrl(longUrl) {
  const apiKey = "###"; // Please set your API key.
  const yourDynamicLinkDomain = "###"; // Please set your dynamic link domain.

  const url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + apiKey;
  const options = {
    payload: JSON.stringify({
      dynamicLinkInfo: {
        dynamicLinkDomain: yourDynamicLinkDomain,
        link: longUrl,
      },
    }),
    contentType: "application/json",
  };
  const res = UrlFetchApp.fetch(url, options);
  const { shortLink } = JSON.parse(res.getContentText());
  return shortLink;
}
  • 当此脚本用于样品电子表格时,请将以下公式放在单元格“ A203”中。

      = importjson(getShortUrl(contatenate(“ https://api.x.immutable.com/v1/orders?include_fees = fees = false&status&status = fall&status = fill&status = fill&status = fill间_by = updated_timestamp& direction = desc&用户= 0x8604808B824C444444DF3F94850ACD584C5AD7D& page_size = 200& cursor =“,w202)),“
     
    • 通过此公式,长度URL用condenate检索(“ https://api.x.immutable.com/v1/orders?include_fees = fees = false = false&status = status=fill by = updated_timestamp&方向= desc&用户= 0x8604808b82444444444df3f94850acd584cd584c5ad7d& page_size = 200& cursor =',w202)并且,使用importjson
    • 使用缩短URL


注意:

  • 此示例脚本假设您已经能够使用Firebase Dynamic Links API。请小心。

  • 当我对您的样本电子表格测试上述脚本和公式时,我确认了这些值已检索。

In your situation, for example, how about the following sample script?

Sample script:

Before you use this script, please set apiKey and yourDynamicLinkDomain. Your yourDynamicLinkDomain might be like https://###.page.link.

const apiKey = "###"; // Please set your API key.
const yourDynamicLinkDomain = "###"; // Please set your dynamic link domain.

function getShortUrl_(longUrl) {

  const url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + apiKey;
  const options = {
    payload: JSON.stringify({
      dynamicLinkInfo: {
        dynamicLinkDomain: yourDynamicLinkDomain,
        link: longUrl,
      },
    }),
    contentType: "application/json",
  };
  const res = UrlFetchApp.fetch(url, options);
  const { shortLink } = JSON.parse(res.getContentText());
  return shortLink;
}

// Please run this function.
function main() {

  // do something for retrieving the long URL in your actual script.
  const longUrl = "###"; // It supposes that your long URL is put to longUrl.

  const shortUrl = getShortUrl_(longUrl); // Here, the long URL is shortned. You can use this.

  // If "options" is required to be used, please use this.
  const options = {

  };
  const res = UrlFetchApp.fetch(shortUrl, options);

}
  • In this sample script, it supposes that by your current script, longUrl is obtained. And, this sample script converts from the long URL to the short URL with the function getShortUrl_. And, you can use this short URL using UrlFetchApp.

Note:

  • This sample script supposes that you have already been able to use Firebase Dynamic Links API. Please be careful about this.

    • If you have never been able to be used Firebase Dynamic Links API, please check the official document. And, the following flow might be useful.
      please check the following flow.

      1. Please create a new Firebase project and link it to your Google Cloud Platform Project. Ref
        • At this time, please set dynamicLinkDomain at "Dynamic Links".
      2. Please enable Firebase Dynamic Links API at the API console.
      3. Please create your API key from your Google Cloud Platform Project.
        • Please use this API in the above script.
  • When I tested this script, I could confirm that the long URL is converted to the short URL and the short URL can be used with UrlFetchApp.

  • If I misunderstood about but I don't know how to use it properly since most of the api calls i make are generated dynamically., please tell me.

References:

Added:

From your following reply,

Hey I made a sample sheet so you can see how I get the longurl it is highlighted with yellow color in 202 row. docs.google.com/spreadsheets/d/… The API works like this: it can pull 200 rows, then on the last row of each call it shows this cursor ID which must be called again in next row in order to show the next 200 rows.

Check the sample sheet on my previous reply. Longurl is highlighted with YELLOW color.

When I saw your sample Spreadsheet, it seems that you are using the long URL as =importjson(CONCATENATE("https://api.x.immutable.com/v1/orders?include_fees=false&status=filled&buy_token_address=0xacb3c6a43d15b907e8433077b6d38ae40936fe2c&order_by=updated_timestamp&direction=desc&user=0x8604808B824C4444Fe4dF3f94850ACd584C5aD7d&page_size=200&cursor=",W202),"","noTruncate,noHeaders"). But unfortunately, from your question and your reply, I couldn't notice that you are using it like that.

In this case, it is required to use my sample script by modifying as follows.

Sample script:

Please copy and paste the following script to the script editor of your Spreadsheet and save the script.

function getShortUrl(longUrl) {
  const apiKey = "###"; // Please set your API key.
  const yourDynamicLinkDomain = "###"; // Please set your dynamic link domain.

  const url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + apiKey;
  const options = {
    payload: JSON.stringify({
      dynamicLinkInfo: {
        dynamicLinkDomain: yourDynamicLinkDomain,
        link: longUrl,
      },
    }),
    contentType: "application/json",
  };
  const res = UrlFetchApp.fetch(url, options);
  const { shortLink } = JSON.parse(res.getContentText());
  return shortLink;
}
  • When this script is used for your sample Spreadsheet, please put the following formula to the cell "A203".

      =importjson(getShortUrl(CONCATENATE("https://api.x.immutable.com/v1/orders?include_fees=false&status=filled&buy_token_address=0xacb3c6a43d15b907e8433077b6d38ae40936fe2c&order_by=updated_timestamp&direction=desc&user=0x8604808B824C4444Fe4dF3f94850ACd584C5aD7d&page_size=200&cursor=",W202)),"","noTruncate,noHeaders")
    
    • By this formula, the long URL retrieved with CONCATENATE("https://api.x.immutable.com/v1/orders?include_fees=false&status=filled&buy_token_address=0xacb3c6a43d15b907e8433077b6d38ae40936fe2c&order_by=updated_timestamp&direction=desc&user=0x8604808B824C4444Fe4dF3f94850ACd584C5aD7d&page_size=200&cursor=",W202) is shorten by shortenUrl(). And, use the shorten URL with importjson.

Note:

  • This sample script supposes that you have already been able to use Firebase Dynamic Links API. Please be careful about this.

  • When I tested the above script and formula to your sample Spreadsheet, I confirmed that the values are retrieved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文