如何使用IGDB API的查询参数格式化URL?

时间:2016-04-04 10:41:25

标签: php jquery ajax api curl

这是我尝试使用的数据库的文档:https://www.igdb.com/api/v1/documentation

我从他们那里请了一个令牌,但它被授予了。

此网址适用于我(我已写完"已编辑" in):https://www.igdb.com/api/v1/games?token=redacted

并返回以下内容:

{"games":[{"id":1,"name":"Thief II: The Metal Age","slug":"thief-ii-the-metal-age","release_date":"2000-03-21","alternative_name":null},{"id":2,"name":"Thief: The Dark Project","slug":"thief-the-dark-project","release_date":"1998-11-30","alternative_name":null},{"id":3,"name":"Thief: Deadly Shadows","slug":"thief-deadly-shadows","release_date":"2004-05-25","alternative_name":null},{"id":4,"name":"Thief","slug":"thief","release_date":"2014-02-25","alternative_name":"Thief 4"},{"id":5,"name":"Baldur's Gate","slug":"baldur-s-gate","release_date":"1998-11-30","alternative_name":null},{"id":6,"name":"Baldur's Gate II: Shadows Of Amn","slug":"baldur-s-gate-ii-shadows-of-amn","release_date":"2000-09-24","alternative_name":null},{"id":7,"name":"Jagged Alliance","slug":"jagged-alliance","release_date":"1994-06-02","alternative_name":null},{"id":8,"name":"Jagged Alliance: Deadly Games","slug":"jagged-alliance-deadly-games","release_date":"1995-01-01","alternative_name":null},{"id":9,"name":"Jagged Alliance 2","slug":"jagged-alliance-2","release_date":"1999-07-23","alternative_name":null},{"id":10,"name":"Jade Empire: Special Edition","slug":"jade-empire-special-edition","release_date":"2005-04-12","alternative_name":null},{"id":11,"name":"Vampire: The Masquerade - Bloodlines","slug":"vampire-the-masquerade-bloodlines","release_date":"2004-11-16","alternative_name":null},{"id":12,"name":"Vampire: The Masquerade - Redemption","slug":"vampire-the-masquerade-redemption","release_date":"2000-06-07","alternative_name":null},{"id":13,"name":"Fallout","slug":"fallout","release_date":"1997-09-30","alternative_name":null},{"id":14,"name":"Fallout 2","slug":"fallout-2","release_date":"1998-09-30","alternative_name":null},{"id":15,"name":"Fallout 3","slug":"fallout-3","release_date":"2008-10-28","alternative_name":null},{"id":16,"name":"Fallout: New Vegas","slug":"fallout-new-vegas","release_date":"2010-10-19","alternative_name":null},{"id":17,"name":"Fallout Tactics: Brotherhood Of Steel","slug":"fallout-tactics-brotherhood-of-steel","release_date":"2001-03-15","alternative_name":null},{"id":18,"name":"Max Payne","slug":"max-payne","release_date":"2001-07-23","alternative_name":null},{"id":19,"name":"Max Payne 2: The Fall Of Max Payne","slug":"max-payne-2-the-fall-of-max-payne","release_date":"2003-10-24","alternative_name":null},{"id":20,"name":"BioShock","slug":"bioshock","release_date":"2007-08-21","alternative_name":null},{"id":21,"name":"BioShock 2","slug":"bioshock-2","release_date":"2010-02-09","alternative_name":null},{"id":22,"name":"System Shock 2","slug":"system-shock-2","release_date":"1999-08-11","alternative_name":null},{"id":23,"name":"System Shock","slug":"system-shock","release_date":"1994-09-22","alternative_name":null},{"id":24,"name":"UFO: Enemy Unknown","slug":"ufo-enemy-unknown--1","release_date":"1994-01-01","alternative_name":null},{"id":25,"name":"X-COM: Terror From The Deep","slug":"x-com-terror-from-the-deep","release_date":"1995-01-01","alternative_name":null}]}

我想要做的是弄清楚如何按标题搜索。例如,如果我只想要拥有术语" Zelda"在其中,我将如何正确格式化URL?

我试过了:

https://www.igdb.com/api/v1/games&q=zelda?token=redacted

返回"禁止"。

我也试过

https://www.igdb.com/api/v1/games?token=redacted&q=zelda

返回上面相同的游戏列表,好像完全不受" Zelda"术语

有人可以就如何正确格式化此URL以执行基于游戏标题的搜索提供建议吗?谢谢!

1 个答案:

答案 0 :(得分:2)

第一个查询参数应该以“?”传递以及以下每个都有“&”。

API的documentation表示您应该直接查询/games/search而不是/games。请试试这个。