【发布时间】:2021-09-24 21:23:50
【问题描述】:
我从Javascript External Adapter Template from Chainlink 制作了一个外部适配器,尝试使用 Spotify API 的客户端凭据流来返回艺术家数据,文档如下所示。 https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow https://developer.spotify.com/console/get-artist/
但是当我尝试通过使用 Axios 进行 API 调用的外部适配器运行相同的调用时,我收到此错误。
这里是 index.js 中外部适配器的主要代码的 sn-p
const customParams = {
artist: [''],
endpoint: false
}
const createRequest = (input, callback) => {
// The Validator helps you validate the Chainlink request data
const apiID = process.env.API_ID
const apiKey = process.env.API_KEY
let token = 'BQDlkzka093OuR4tL7XyaI-Tag4R166FQGBSogBP6hEBxhsCjH8XfMRqs_apKFk0T87FGIrwPtT1bkuGCeE';
const validator = new Validator(callback, input, customParams)
const jobRunID = validator.validated.id
const endpoint = validator.validated.data.endpoint
const artistID = validator.validated.data.artist.toUpperCase()
const url = `https://api.spotify.com/v1/artists/${artistID}`
const params = {
artistID
}
// curl -X "GET" "https://api.spotify.com/v1/artists/5K4W6rqBFWDnAN6FQUkS6x" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer authtoken"
// This is where you would add method and headers
// you can add method like GET or POST and add it to the config
// The default is GET requests
// method = 'get'
// headers = 'headers.....'
const head = {
'Accept' : 'application/json',
'Content-Type' : 'application/json',
'Authorization' : 'Bearer ' + token
}
const config = {
url,
headers: head
}
console.log("config:", config)
这是我在终端中运行以传递 Spotify 艺术家 ID 的命令
curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "": "5K4W6rqBFWDnAN6FQUkS6x"} }'
-编辑-
只是为了表明代码并非完全错误,我可以通过外部适配器调用此 url https://jsonplaceholder.typicode.com/posts/5,并使用此命令传入 5。
curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "": "5"} }'
【问题讨论】:
标签: javascript blockchain solidity smartcontracts chainlink