我正在使用地理定位,我在客户端处理所有事情,现在我想从
处理这个问题目前使用它作为;
var url = "youtube.com",
options = {
key: API_KEY,
video: "vid_id"
};
$.get(url, options, function(data) {
console.log(data)
})
我想将它与nodeJS HTTPS一起使用,所以我尝试了;
var https = require("https"),
url = "youtube.com",
options = {
key: API_KEY,
video: "vid_id"
};
https.get(url, options, function(data) {
console.log(data)
})
但我无法让它工作,我希望有人可以转换它。
最佳答案
尝试使用 Node.js 的 request
模块。通过运行安装它:
npm 安装请求
。
var request = require('request');
request(`youtube.com/?key=${key}&video=${video_id}`, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('body:', body); // Print body of the response.
});
关于javascript - 将 $.get 转换为 node.js 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45070482/