【问题标题】:Import IsThereAnyDeal waitlist to Google sheets将 IsThereAnyDeal 候补名单导入 Google 表格
【发布时间】:2021-04-19 03:43:24
【问题描述】:

我正在尝试从 IsThereAnyDeal.com 导入我的完整愿望清单,默认情况下它只会加载 75 个结果,直到您向下滚动,所以我觉得我可能需要开始使用他们的 API。

我曾尝试使用这样的链接作为示例,但它会搜索网站上的游戏列表。 https://api.isthereanydeal.com/v02/search/search/?key=&q=hades

我希望自动执行此操作以避免定期手动导出

作为参考,这是当前的候补名单以及我希望从 https://isthereanydeal.com/u/01bc9/waitlist/ 导入的内容

【问题讨论】:

  • 你可能想学习如何使用UrlFetchApp.fetch()
  • 库珀就是这么想的,我只是还没有确定完成这项工作所需的一切
  • 可以问一下你要使用的API官方文档吗?
  • 对不起,是的,这里是这个api的官方文档itad.docs.apiary.io/#reference/waitlist
  • 感谢您回复并添加更多信息。从你的回复中,我提出了一个答案。你能确认一下吗?如果这不是您期望的结果,我深表歉意。

标签: api google-apps-script google-sheets google-sheets-formula


【解决方案1】:

我相信你的目标和你目前的情况如下。

  • 来自your provided official document,我想你可能会使用“Waitlist”中的“Waitlist”的方法。

  • 当我看到示例 curl 命令时,如下所示。

      curl --include \
      'https://api.isthereanydeal.com/v01/user/wait/all/?access_token=###'
    
  • 并且,示例响应如下。

      {
        "data": {
          "falloutnewvegas": {
            "title": "Fallout: New Vegas"
          },
          "racesun": {
            "title": "Race the Sun"
          },
          "vessel": {
            "title": "Vessel"
          }
        }
      }
    
  • 您想使用 Google Apps 脚本实现上述请求。

  • 而且,您已经获得了使用 API 的有效访问令牌。

如果我的理解是正确的,当上面的 curl 命令转换为 Google Apps Script 时,它变成如下。

示例脚本:

请将以下脚本复制并粘贴到电子表格的脚本编辑器中并保存。并且,请设置accessToken和sheetName的变量,并运行函数。

function myFunction() {
  const accessToken = "###"; // Please set your access token.
  const sheetName = "Sheet1";  // Please set the sheet name.

  // Retrieve the values from API.
  const url = "https://api.isthereanydeal.com/v01/user/wait/all/?access_token=" + accessToken;
  const res = UrlFetchApp.fetch(url);
  console.log(res.getContentText()) // You can confirm the response value at the log.
  const obj = JSON.parse(res.getContentText());

  // Put the retrieved values to Spreadsheet.
  const values = Object.entries(obj.data).map(([k, {title}]) => [k, title]);
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
}
  • 如果访问令牌出错且访问令牌包含特定字符,请将const url = "https://api.isthereanydeal.com/v01/user/wait/all/?access_token=" + accessToken;修改为const url = "https://api.isthereanydeal.com/v01/user/wait/all/?access_token=" + encodeURIComponent(accessToken);

注意:

  • 在此示例脚本中,它假定您的访问令牌可用于 API。请注意这一点。
  • 很遗憾,根据您的问题,我找不到您期望的输出情况。但我知道您想将检索到的值放到电子表格中。所以在这个示例脚本中,键和值的标题被放入电子表格。当你想改变格式时,请修改上面的脚本。
  • 当我看到你提供的官方文档时,上面写着Get list of games that the user has in Waitlist.。但是我找不到关于响应值数量的文档。所以我不确定这个方法的响应值的最大数量。

参考资料:

【讨论】:

  • 非常感谢您的回答,我会在第二天尝试。我对脚本和 API 还是很陌生。我难以理解的一件大事是我从哪里获得访问令牌。我是想出那个还是我需要从某个地方抓住它?
  • @Charles 感谢您的回复。当我的回答对您的情况没有帮助时,我深表歉意。关于The big thing I've had trouble understanding is where do I get the accesstoken from. Do I come up with that or do I need to grab that from somewhere?的新问题,我建议您查看the official document。如果您对此无法理解,我建议您联系 API 方面的人员或将其作为新问题发布。很抱歉,我不熟悉您使用的 API。
  • 感谢您的帮助!我去了 isthereanydeal 应用程序网站,添加了一个重定向 uri 和一个应用程序可用的 url(两者都是虚构的),然后我才能授权我的应用程序读取我的愿望清单。之后我从地址栏中取出令牌并将其插入您提供的代码中,它现在可以正常工作了!我只需要解析数据,让它以我期望的方式显示。
  • @Mathx2 感谢您的回复和测试。我很高兴你的问题得到了解决。也谢谢你。
猜你喜欢
  • 1970-01-01
  • 2014-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 2022-06-14
  • 2023-04-03
相关资源
最近更新 更多