我正在尝试获取一些user.it在本地主机上工作的概要信息,但没有在服务器上运行,我没有登录本地/我的pc.It上的instgram帐户,这看起来像在服务器上,它首先尝试登录。
let username = req.query.username;
if (!username) {
throw "Please enter a username";
}
let name = username.toLowerCase();
// console.log("name", name);
var instagram_url = `https://www.instagram.com/${name}/?__a=1`;
// console.log("url", instagram_url);
// let response = await axios.get(
// `https://api.lamadava.com/v1/user/by/username?username=hamimkivines&access_key=${access_key}
// );
let response = await fetch(instagram_url);
console.log("response -", response);
let profile = await response.json();
// console.log("profile", profile);
return res.status(200).send(profile);
**Local response -**
[Symbol(Response internals)]: {
url: 'https://www.instagram.com/hamimkivines/?__a=1',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
**Server Response**
0|dev | [Symbol(Response internals)]: {
0|dev | url: 'https://www.instagram.com/accounts/login/',
0|dev | status: 200,
0|dev | statusText: 'OK',
0|dev | headers: Headers { [Symbol(map)]: [Object: null prototype] },
0|dev | counter: 1
0|dev | }
0|dev |
0|dev | error FetchError: invalid json response body at https://www.instagram.com/accounts/login/ reason: Unexpected token < in JSON at position 0
0|dev | at /var/www/html/everlensv2node/node_modules/node-fetch/lib/index.js:273:32
0|dev | at processTicksAndRejections (internal/process/task_queues.js:95:5)
0|dev | at async getInstagramProfile (/var/www/html/everlensv2node/modules/user/user.controller.js:188:21) {
0|dev | type: 'invalid-json'
0|dev | }
发布于 2021-12-22 08:02:33
这是由API端点返回包含JSON数据的HTML标记引起的。而不是使用response.json()
尝试
let profile = response.text()
let parsed_json = JSON.parse(profile)
如果这样做不起作用,您将不得不手动删除正在返回的XML的封闭标记。
https://stackoverflow.com/questions/70445305
复制相似问题