我的编码知识很不稳定,因为我没有有序地学习它。现在,我正在尝试发送一个 cURL 请求,文档是:
curl https://api.at356.com/studio/v1/sd-large/complete
-H 'Content-Type: application/json'
-H 'Authorization: Bearer YOUR_API_KEY'
-X POST
-d '{"prompt": “生活就像”,“numResults”:1,}'
这是代码
function searchFor(query) {
// Base URL to access
var urlTemplate = "https://api.at356.com/studio/v1/sd-large/complete "
// Script-specific credentials & search engine
var ApiKey = "shwMCMgEviwfz6X7Rvbtna6";
var prompt = {
"prompt": query,
"numResults": 1,
}
// Build custom cURL
var cURL = {
'method': 'POST',
"headers":{
"Content-type": "application/json",
"Authorization": ApiKey,
},
prompt,
"muteHttpExceptions": true,
"followRedirects": true,
"validateHttpsCertificates": true
};
// Perform Request
//Logger.log( UrlFetchApp.getRequest(urlTemplate, params) ); // Log query to be sent
var response = UrlFetchApp.fetch(urlTemplate, cURL,);
var respCode = response.getResponseCode();
if (respCode !== 200) {
throw new Error("Error " + respCode + " " + response.getContentText());
} else {
// Successful search, log & return results
var result = JSON.parse(response.getContentText());
Logger.log("Obtained %s search results in %s seconds.",
result.searchInformation.formattedTotalResults,
result.searchInformation.formattedSearchTime);
return result;
}
}
谁能告诉我我做错了什么以及如何解决它