【问题标题】:Why are my template variables allegedly missing from my YQL query?为什么我的 YQL 查询中据称缺少我的模板变量?
【发布时间】:2015-01-13 17:02:08
【问题描述】:

我正在尝试在 YQL 查询中隐藏 API 密钥。为此,我尝试关注this post(也由同一作者here 解释)。当我尝试使用 URI 模板运行查询时,我收到以下警告:

"warning": "Missing template variables (BungieAPIKey)"

以下是我采取的步骤:

  1. 通过运行 insert into yql.storage.admin (value) values ("set BungieAPIKey='YOUR_KEY' on uritemplate;") 将 API 密钥保存在 yql.storage.admin
  2. 使用返回的执行密钥 (https://developer.yahoo.com/yql/console/?env=store://XXXXXXXXXX) 将环境加载到控制台中
  3. 运行select * from json where url in (select url from uritemplate where template='http://bungie.net/videos/{BungieAPIKey}/{user}/{page}' and user='foo' and page='bar')

这是返回的 JSON:

{
 "query": {
  "count": 0,
  "created": "2015-01-13T16:58:57Z",
  "lang": "en-US",
  "diagnostics": {
   "publiclyCallable": "true",
   "warning": "Missing template variables (BungieAPIKey)",
   "redirect": {
    "from": "http://bungie.net/videos//foo/bar",
    "status": "301",
    "content": "http://www.bungie.net/videos/foo/bar"
   },
   "url": {
    "execution-start-time": "0",
    "execution-stop-time": "573",
    "execution-time": "573",
    "http-status-code": "404",
    "http-status-message": "Not Found",
    "content": "http://bungie.net/videos//foo/bar"
   },
   "error": "Invalid JSON document http://bungie.net/videos//foo/bar",
   "user-time": "574",
   "service-time": "573",
   "build-version": "0.2.212"
  },
  "results": null
 }
}

为了缩小问题范围,我在干净的 YQL 控制台(没有设置环境)中尝试了以下查询:

set BungieAPIKey='YOUR_KEY' on uritemplate;
select url from uritemplate where template='http://bungie.net/videos/{BungieAPIKey}/'

Running this 给了我同样的警告。 为什么我的模板变量没有从我设置的环境变量中提取?

【问题讨论】:

    标签: environment-variables yql api-key uritemplate


    【解决方案1】:

    由于某种原因,uritemplate 上的 set x='y' 似乎没有被兑现。 如果没有这个,您可以选择拥有一个接受类型化参数的自定义表,例如 apiKey。然后,您可以拥有以下内容:

     use 'http://location-of-custom-table' as tablename;
     set apiKey='foo' on tablename;
     select * from tablename; 
    

    在上述情况下,apiKey 将被传递到自定义表中,您可以将其附加到 javascript 中并创建您的 url。

    【讨论】:

    • 感谢您的回复!您的解决方案现在必须有效,我将尝试进一步调查 SET 不合作的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    相关资源
    最近更新 更多