JavaScript 代码示例
本页面提供 JavaScript/Node.js 调用哼哼猫 API 的完整示例。
🚀 使用 Fetch API
const apiUrl = "https://api.meowload.net/openapi/extract/post";
const apiKey = "your-api-key-here";
fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
"accept-language": "zh"
},
body: JSON.stringify({
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
})
})
.then(response => {
if (!response.ok) {
return response.json().then(error => {
throw new Error(`${response.status}: ${error.message}`);
});
}
return response.json();
})
.then(data => {
console.log(`✅ 提取成功!媒体数量: ${data.medias.length}`);
data.medias.forEach(media => {
console.log(`- ${media.media_type}: ${media.resource_url}`);
});
})
.catch(error => {
console.error(`❌ 请求失败: ${error.message}`);
});📦 使用 Axios(Node.js)
npm install axiosconst axios = require('axios');
const apiUrl = "https://api.meowload.net/openapi/extract/post";
const apiKey = "your-api-key-here";
axios.post(apiUrl, {
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}, {
headers: {
"x-api-key": apiKey,
"accept-language": "zh"
}
})
.then(response => {
const data = response.data;
console.log(`✅ 提取成功!媒体数量: ${data.medias.length}`);
})
.catch(error => {
if (error.response) {
console.error(`- 请求失败 (${error.response.status}): ${error.response.data.message}`);
} else {
console.error(`❌ 网络错误: ${error.message}`);
}
});🎯 使用 async/await
async function extractPost(url, apiKey) {
try {
const response = await fetch("https://api.meowload.net/openapi/extract/post", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey
},
body: JSON.stringify({ url })
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
return await response.json();
} catch (error) {
console.error(`提取失败: ${error.message}`);
return null;
}
}
// 使用
const result = await extractPost("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "your-api-key-here");