Can I call the Twitter API in client using Fetch?

前端 未结 2 1019
抹茶落季
抹茶落季 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]}"`,
    }
    

    });

提交回复
热议问题