Skip to content Skip to sidebar Skip to footer

Can I Call The Twitter Api In Client Using Fetch?

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_credentials.json. Response to p

Solution 1:

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]}"`,
}

});

Solution 2:

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

Post a Comment for "Can I Call The Twitter Api In Client Using Fetch?"