我使用下面的URL在Qlik Sense中建立了一个REST连接,但我使用的URL只返回玩家ID为237的数据。我想返回播放器库下的所有数据,而不是一个特定的ID。
http://api.football-api.com/2.0/player/237?Authorization=0123456789
我尝试使用星号(*)而不是237,它不起作用,我想知道查询参数或查询标题字段是否可能是解决方案。我看到填充REST连接表单的所有示例都很简单,在这种情况下没有帮助。
你不能用player
替换*
并期望获得所有数据。这不是REST API的工作方式。理想情况下你应该有players
(例如)终点,它应该返回所有玩家的列表(包括他们id
),然后遍历它们的所有(或子集)以获得更多细节。据我所知,football-api.com
api文档中没有这样的端点。如果他们可以为您提供此类信息,可能最好联系他们的支持团队
在Qlik中,此解决方案可能如下所示:
// Lets imagine that this table is the API response that
// returns list with all players
Players:
Load * Inline [
playerId
1
2
3
4
5
];
// Loop through all values in playerId field
for i = 0 to FieldValueCount('playerId')
// vPlayerId variable will hold the current iteration player id
let vPlayerId = FieldValue('playerId', $(i))
// Load player data. The player id variable is in the url
Details:
Load
*
From
http://api.football-api.com/2.0/$(vPlayerId)/237?Authorization=0123456789
;
next
// We can drop the Players table if not needed anymore
Drop Table Players;
顺便说一句试试,不要把Authorization
键这样的东西放在互联网上。
文档:qazxsw poi
假设player_id是必需的,你无法使用*全部下载。
我认为绕过它的方法是通过播放器逐个询问玩家使用循环:
https://football-api.com/documentation2/#!/Player/get_player_player_id
您可以使用变量而不是数字。
我无法查看数据,因为我没有授权,需要知道URL中playerID的总数。
FOR i=1 to 1000
// your code here just get player using $(i) as id
// you can save also player data as qvd so you will not ask another time for that
// (most api have plimitation with number of calls)
NEXT i
我希望你觉得这对你有帮助 :)
----补充----
我检查了api。
只需运行从1到数字的循环将导致404错误。 (非常规参数)
你需要9002队的球员吗? 如果是这样,9002队的player_id可以在根下找到小队。 (休息连接→选择要加载的数据→root>小队)
因此,您可以先获取小队表的id字段,然后循环id。
步骤1)
将Rest Connector连接到团队API。
// Variable setting, Total Row of PlayerID's Number.
let Id = FieldValue('playerId', 1);
//or
let Id = total number;
// Loop Start
for start = 1 to $(ID)
// exampleQuery
RestConnectorMasterTable:
SQL SELECT
"__KEY_...."
(SELECT ....
FROM ...)
FROM XML ...
WITH CONNECTION(Url "http://api.football-api.com/2.0/player/$(start)?Authorization=0123456789");
/* put a variable instead of ID's number in the WITH CONNECTION statement. */
// Loop End
Next start;
Play:
Load *
Resident RestConnectorMasterTable
Where Not IsNull([__FK_...]);
Drop table RestConnectorMasterTable;
team的参数是9002。
第2步) 单击选择要加载的数据以选择root下的小队数据。 并且只有id字段进入班组表。 (共28行) http://api.football-api.com/2.0/team/9002?Authorization=1234567890
stpe 3) 在现有的player_id RestConnector选项中将分页类型设置为Custom。 (创建连接语句。) enter image description here
第4步) 请参阅下面的脚本和执行加载。
enter image description here
听到结果:
// Team API Connect
LIB CONNECT TO 'Football_Team';
RestConnectorMasterTable:
SQL SELECT
"__KEY_root",
(SELECT
"id",
"name",
"__FK_squad"
FROM "squad" FK "__FK_squad")
FROM JSON (wrap on) "root" PK "__KEY_root";
[squad]:
LOAD [id] AS [id],
[name] AS [name]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_squad]);
DROP TABLE RestConnectorMasterTable;
// Player_Id API Connect
LIB CONNECT TO 'Football_playerId';
LET total = NoOfRows('squad'); // Number of total.
For i = 0 to $(total) - 1
LET vID = Peek('id', $(i), 'squad'); // Loop start id by 9002 team.
// The following default script was commented out unnecessarily.
// Action required: Implement the logic to retrieve the total records from the REST source and assign to the 'total' local variable.
// Let total = 0;
// Let totalfetched = 0;
// Let startAt = 0;
// Let pageSize = 100;
// for startAt = 0 to total step pageSize
RestConnectorMasterTable:
SQL SELECT
"id" AS "id_u3",
"common_name",
"name" AS "name_u3",
"firstname",
"lastname",
"team",
"teamid",
"nationality",
"birthdate",
"age",
"birthcountry",
"birthplace",
"position",
"height",
"weight",
"__KEY_root"
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(Url "http://api.football-api.com/2.0/player/$(vID)?Authorization=0123456789");
// player/id? → Change the ID to a variable. *****
// Action required: change URL included in 'WITH CONNECTION' as needed to support pagination for the REST source.
// Please see the documentation for "Loading paged data."
// NEXT startAt;
[Player]:
LOAD [id_u3] AS [id_u3],
[common_name] AS [common_name],
[name_u3] AS [name_u3],
[firstname] AS [firstname],
[lastname] AS [lastname],
[team] AS [team],
[teamid] AS [teamid],
[nationality] AS [nationality],
[birthdate] AS [birthdate],
[age] AS [age],
[birthcountry] AS [birthcountry],
[birthplace] AS [birthplace],
[position] AS [position],
[height] AS [height],
[weight] AS [weight]
// , [__KEY_root] AS [__KEY_root]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_root]);
DROP TABLE RestConnectorMasterTable;
Next i; // Loop End.
DROP TABLE squad; // id info table delete.
希望你得到你想要的结果:D