我找到了一个有趣的解决方案here来获取Instagram公开个人资料照片。
var name = "smena8m",
items;
$.getJSON("https://query.yahooapis.com/v1/public/yql?callback=?", {
q: "select * from json where url='https://www.instagram.com/" + name + "/?__a=1'",
format: "json"
}, function(data) {
console.log(data);
if (data.query.results) {
items = data.query.results.json.user.media.nodes;
$.each(items, function(n, item) {
$('body').append(
$('<a/>', {
href: 'https://www.instagram.com/p/'+item.code,
target: '_blank'
}).css({
backgroundImage: 'url(' + item.thumbnail_src + ')'
}));
});
}
});
我想在我的nodejs app中做同样的事情:
var request = require('request');
var name = "smena8m";
var propertiesObject = { q: "select * from json where url='https://www.instagram.com/" + name + "/?__a=1'" };
var myurl = "https://query.yahooapis.com/v1/public/yql?callback=?";
var items;
request.get(myurl, { qs:propertiesObject}, function(err, response, body) {
if(err) { console.log(err); return; }
console.log("Get response: " + response.statusCode);
if (body.data.query.results) {
items = body.data.query.results.json.user.media.nodes;
items.forEach(function(n, item) {
var itemCodes = 'https://www.instagram.com/p/'+item.code;
var thumbnails = item.thumbnail_src;
console.log('here: ', itemCodes, thumbnails);
});
}
});
但我的body
返回空。有人可以帮我在nodejs中实现同样的目标吗?
响应代码 200 且正文为空。
答案 0 :(得分:-2)
将myurl改为:
myurl='https://www.instagram.com/' +name '/?__a=1';
并更改此行request.get(myurl, { qs:propertiesObject}, function(err, response, body) {
为:
request.get(myurl, {}, function(err, response, body) {
console.log(body)然后你应该开心!