[英]Am I able to download the data from a Google Spreadsheet with the Drive API?
[英]I am getting information from an API but i am not able to use it
我想通过我的PHP文件启动Node js应用程序。 之后,我想将结果保存在$ result之类的变量中
数据如下所示:
[{ id: 'ID', displayName: 'DisplayedName' },
{ id: 'ID', displayName: 'DisplayedName' },
...]
而且我不知道该如何使用。
我的问题:
这是功能之一
static get Sth1() { return "sth1" }
static get Sth2() { return "sth2" }
static get Sth3() { return "sth3" }
getMeSth(platform,type) {
return new Promise((resolve, reject) => {
if (!(platform == "pc" || platform == "ps4" || platform == "xb1")) {
reject("Please precise a good platform: ps4/xb1/pc")
}
if(!(type == this.constructor.Sth1 || type == this.constructor.Sth2 || type == this.constructor.Sth3)) {
reject("Please precise a good type test.Sth1/test.Sth2/test.Sth3")
}
request({
url: EndPoint.leaderBoardScore(platform,type),
headers: {
Authorization: "author " + this.access_token
},
method: "POST",
json: true
}).then(leaderboard => {
leaderboard = leaderboard.entries
leaderboard.forEach(i => {
i.accountId = i.accountId.replace(/-/g,'')
})
request({
url: EndPoint.displayNameFromIds(leaderboard.map(i => i.accountId)),
headers: {
Authorization: "author " + this.access_token
},
method: "GET",
json: true
}).then(displayNames => {
leaderboard.forEach(i => {
i.displayName = displayNames.find(ii => ii.id === i.accountId).displayName
})
resolve(JSON.stringify(leaderboard))
})
.catch(err => {
reject(err)
})
})
.catch(err => {
reject(err)
})
})
}
现在,我将JSON.stringify()内置到应用程序中,就得到了此数据
[{"accountId":"ID1","value":913,"rank":1,"displayName":"Name1"},{"accountId":"ID2","value":892,"rank":2,"displayName":"Name2"},{"accountId":"ID3","value":868,"rank":3,"displayName":"Name3"},...]
我如何提取重要信息,例如Value / Rank / DisplayName ???
我刚刚在结尾处添加了{"leaderboard":
,最后添加了}
。 现在,它是一个带有数组的JSON对象,其中包含许多其他对象。
$output = "{\"leaderboard\"" . ":" . exec('node /path/to/node/js/file/doSth.js &') . "}";
现在我的$output
是
{"leaderboard":[{"accountId":"ID1","value":913,"rank":1,"displayName":"Name1"},{"accountId":"ID2","value":892,"rank":2,"displayName":"Name2"},{"accountId":"ID3","value":868,"rank":3,"displayName":"Name3"},...]}
我可以用提取我的信息
$DName = json_decode($output, true);
echo $DName['leaderboard'][0]['displayName'];
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.