簡體   English   中英

如何在React Native訪存中使用授權標頭使用Yelp API進行獲取請求

[英]How to use Authorization Header in React Native fetch to make a get request using Yelp API

我試圖在react-native中使用FETCH發出發布請求。 我收到驗證錯誤。 我在這里想念什么?

    _fetchYelp(){

          let data = {
              method: 'POST',
              body: JSON.stringify({
                  'client_id': 'id',
                  'client_secret': 'secret',
                  'grant_type': 'client_credentials'
              }),
             headers: {
                  'Accept':       'application/json',
                  'Content-Type': 'application/x-www-form-urlencoded'
                     }
            }
         return fetch('https://api.yelp.com/oauth2/token', data)
                .then(response => response.json());

         }


      Error 

      status   400
      timeout  0 
      response {"error":{"code":"VALIDATION_ERROR",
                "description":"client_id or client_secret parameters          not found. Make sure to provide client_id and client_secret in the body with the application/x-www-form-urlencoded content-type"}}
      response_url https://api.yelp.com/oauth2/token

謝謝。

getAccessToken() {

    let formData  = new FormData();
    formData.append('grant_type', 'client_credentials')
    formData.append('client_id', 'yourID')
    formData.append('client_secret', 'yourSecret')
    let headers = new Headers();

    return fetch('https://yourBaseUrl/oauth2/token/', {
        method: 'POST',
        headers: headers,
        body: formData,
    })
    .then((response) => response.json())      
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM