【发布时间】:2021-09-18 00:38:27
【问题描述】:
我正在尝试在客户端使用 opengraph.io。他们有 jQuery 的文档,我的代码基于: https://www.opengraph.io/examples/jquery-opengraph-example/
const url = 'http://cnet.com';
const urlEncoded = encodeURIComponent(url);
const apiKey = 'MY-KEY';
const requestUrl = 'https://opengraph.io/api/1.1/site/' + urlEncoded + '?app_id=' + apiKey;
fetch(requestUrl).then(res => {
console.log(res);
console.log(res.body);
});
我从res 得到的回复似乎是成功的,但没有我需要的数据。
body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: ""
type: "cors"
url: "https://opengraph.io/api/1.1/site/http%3A%2F%2Fcnet.com?app_id=MY-KEY"
我尝试注销res.body,但它只是返回:
ReadableStream {locked: false}
我在这里发现了一个类似的问题,但 API 似乎返回了 res.data,这对我来说不是这样:
How to get Open Graph meta from URL input on the client side
【问题讨论】:
标签: javascript fetch