Node.js 拆分Goole播放结果
我有一个React前端和一个节点后端,我所要做的就是使用Facundo Olano的从Google Play商店中获取一些数据 这是我的前端Node.js 拆分Goole播放结果,node.js,reactjs,Node.js,Reactjs,我有一个React前端和一个节点后端,我所要做的就是使用Facundo Olano的从Google Play商店中获取一些数据 这是我的前端 import React, {Component} from 'react'; import './App.css'; export default class App extends Component { state = { title: '', review: '' }; component
import React, {Component} from 'react';
import './App.css';
export default class App extends Component {
state = {
title: '',
review: ''
};
componentDidMount() {
this.callApi()
.then(res => this.setState({
title: res.title,
review: res.review
}))
.catch(err => console.log('Error: ', err));
}
callApi = async () => {
const response = await fetch('/gPlay');
const body = await response.json();
if (response.status !== 200) {
throw Error(body.message);
}
return body;
};
render() {
console.log("==================== app log ====================");
console.log("State: ", this.state);
return (
<div className="App">
<p>Title: {this.state.title}.</p>
<p>Review: {this.state.review}.</p>
</div>
);
}
}
这是我得到的结果的一小部分
{
price: 6.99,
free: false,
currency: 'USD',
priceText: '$6.99',
offersIAP: true,
size: 'Varies with device'
}
我根据文档得到了完整的结果,但我需要能够将返回的对象拆分,以便能够将其中的一部分发送回前端,但我一生都无法让它工作
我想我可以简单地做一些事情,比如gplaydresults.price
,并返回6.99,但返回的都是未定义的
请有人帮忙,我一定是错过了什么,因为这肯定不会那么难
谢谢xxx好的,我算出来了!:)
对于任何感兴趣的人,gPlayResults
被分配了一个Promise
,而不是我期望的对象
我使用进行了一次回调。然后就可以使用我需要的结果将一个可用对象发送回前端
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
const googlePlayApp = require('google-play-scraper');
const appToScrape = 'com.mojang.minecraftpe';
app.get('/gPlay', (req, res) => {
console.log('==================== /gPlay ====================');
const gPlayResults = googlePlayApp.app({appId: appToScrape});
gPlayResults.then(function(result) {
res.send({
appObject: result
})
});
});
app.listen(port, () => console.log(`Listening on port: ${port}`));
关于下一个问题
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
const googlePlayApp = require('google-play-scraper');
const appToScrape = 'com.mojang.minecraftpe';
app.get('/gPlay', (req, res) => {
console.log('==================== /gPlay ====================');
const gPlayResults = googlePlayApp.app({appId: appToScrape});
gPlayResults.then(function(result) {
res.send({
appObject: result
})
});
});
app.listen(port, () => console.log(`Listening on port: ${port}`));