Can I call the Twitter API in client using Fetch?

前端 未结 2 1016
抹茶落季
抹茶落季 2021-01-23 21:06

I am trying to call the Twitter API in a React App and get the following error

Fetch API cannot load https://api.twitter.com/1.1/account/verify_credenti

相关标签:
2条回答
  • 2021-01-23 21:37

    I do not know wether or not the Twitter API allows CORS, but if it does, specifying cors mode in your request should do the trick

    const response = await fetch(baseUrl, {
      method: `${HTTP_GET}`,
      mode: 'cors',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `OAuth ${oauthKeys[0]}="${oauthValues[0]}",${oauthKeys[1]}="${oauthValues[1]}",oauth_signature="${signature}",${oauthKeys[2]}="${oauthValues[2]}",${oauthKeys[3]}="${oauthValues[3]}",${oauthKeys[4]}="${oauthValues[4]}",${oauthKeys[5]}="${oauthValues[5]}"`,
    }
    

    });

    0 讨论(0)
  • 2021-01-23 21:45

    I had to create a Node server to call the API, no biggie

    0 讨论(0)
提交回复
热议问题