从Petfinder获取API时遇到问题

时间:2019-11-07 00:47:53

标签: api react-native

我目前正在尝试从petFinder https://github.com/helenuria/Petfinder-API获取一个api。但是,它没有按照教程中的说明返回预期的对象,不确定我是否可能使用react native提取了错误

以下是Im用于获取api的代码:

const PET_API = 'http://api.petfinder.com/pet.getRandom?key=' + 'key' + '&animal=cat&location=' + '34758' + '&output=basic&format=json&callback=?'

 getAdopt = async () => {
    const permission = await Permissions.askAsync(Permissions.LOCATION)
    if (permission.status === 'granted') {
      const location = await Location.getCurrentPositionAsync()
      const url = PET_API
      const response = await fetch(url)
      //const data = await response.json()
      let res = JSON.stringify(response);



     console.log(response)
    }
  }

It however only returns the following object and not the object the tutorial states, am I fetching the API incorrectly? 

Response {
  "_bodyBlob": Blob {
    "_data": Object {
      "blobId": "C573AEBC-6977-4CA5-8E19-62EDE29A7836",
      "name": "pet.getRandom",
      "offset": 0,
      "size": 381,
      "type": "text/plain",
    },
  },
  "_bodyInit": Blob {
    "_data": Object {
      "blobId": "C573AEBC-6977-4CA5-8E19-62EDE29A7836",
      "name": "pet.getRandom",
      "offset": 0,
      "size": 381,
      "type": "text/plain",
    },
  },
  "headers": Headers {
    "map": Object {
      "content-encoding": "gzip",
      "content-length": "263",
      "content-type": "text/plain",
      "date": "Wed, 06 Nov 2019 02:28:10 GMT",
      "vary": "Accept-Encoding",
      "via": "1.1 46cf8c846d441a6db760cf4a1563952f.cloudfront.net (CloudFront)",
      "x-amz-apigw-id": "CtxlKF1zIAMFjNA=",
      "x-amz-cf-id": "ZTQfkx8z3XsxOPKc8jS0qFwu9SJ_GGP1XkN4-56NVXhkJbZVm5YdbA==",
      "x-amz-cf-pop": "DFW53-C1",
      "x-amzn-remapped-connection": "keep-alive",
      "x-amzn-remapped-content-length": "263",
      "x-amzn-remapped-date": "Wed, 06 Nov 2019 02:28:10 GMT",
      "x-amzn-requestid": "8c328e78-9f2b-4932-9b4e-116dc11463e9",
      "x-cache": "Miss from cloudfront",
      "x-frame-options": "SAMEORIGIN",
    },
  },
  "ok": true,
  "status": 200,
  "statusText": undefined,
  "type": "default",
  "url": "https://api.petfinder.com/pet.getRandom?key=m0WnJCF0mjps6U8eNmX2V7zbwmoG1ra6ZAOZifDObMnDPxgBgs&animal=cat&location=34758&output=basic&format=json&callback=?",
}

0 个答案:

没有答案