gatsby - GatsbyJS : 将调用 Hubspot API 的脚本放在哪里
问题描述
我需要将用户信息从 Hubspot 提取到我在 AWS Amplify 上托管的 Gatsby 站点。在他们的文档中,在 NodeJS 下,他们提供了一些示例代码:
var request = require("request");
var options = { method: 'GET',
url: 'https://api.hubapi.com/contacts/v1/contact/vid/12627374/profile',
qs: { hapikey: 'demo' }
}
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
我只是不确定该代码应该在哪里,以便我可以动态提取数据。它应该放在 gatsby-browser.js 下吗?还是我需要一个额外的模块,比如 Axios 或 Express ?还是它在我的 AWS 安装中的某个地方?
谢谢 !
解决方案
在 return 语句之前,我在组件中使用它获得了交易数据:
export default function AppHub () {
const [deals, setDeals] = useState([]);
useEffect(() => {
fetch(`https://api.hubapi.com/crm/v3/objects/deals?hapikey=YOURKEYHERE&limit=100`,
)
.then(response => response.json()) // parse JSON from request
.then(dealsapi => {
console.log(dealsapi);
setDeals(dealsapi.results);
})
.catch(console.error);
}, []);
推荐阅读
- javascript - 单击分页按钮后如何使表格可见?
- laravel - Laravel 登录使用 make:auth
- amazon-web-services - AWS KMS 每秒请求限制的解决方法
- python-sphinx - 如何使用 Sphinx 链接本地 Python 帮助文档
- java - JOptionPane.showMessageDialog 必须退出两次
- javascript - 使用共享 mouseOver 处理程序的 React 组件
- python - Django 2.0 教程 - /polls/1/vote/ 'ReverseManyToOneDescriptor' 对象的 AttributeError 没有属性 'get'
- c++ - C++:
未能声明函数 CTL_HW 和 HW_NCPU - solr - 具有大量数据的完整构建 solr 索引
- oauth - Facebook 更改我的 Oauth 重定向 URL