0

YQL クエリ内で API キーを隠そうとしています。そうするために、私はこの投稿に従ってみました(同じ著者によってここでも説明されています)。URI テンプレートを使用してクエリを実行しようとすると、次の警告が返されます。

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

これが私が取ったステップです:

  1. yql.storage.adminを実行して API キーを保存します。insert into yql.storage.admin (value) values ("set BungieAPIKey='YOUR_KEY' on uritemplate;")
  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}/'

これを実行すると、同じ警告が表示されます。テンプレート変数が、環境変数として設定したものからプルされないのはなぜですか?

4

1 に答える 1

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 を作成できます。

于 2015-01-13T19:45:10.973 に答える