Can I call the Twitter API in client using Fetch?

假如想象 提交于 2019-12-02 10:07:12

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

});

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!