Twitter API authorization fails CORS preflight in browser

前端 未结 4 1493
说谎
说谎 2020-11-29 09:55

I\'m trying to do the 3-legged authorization necessary to call the Twitter APIs in a browser. The process starts with getting a request token by POSTing a signed request to

4条回答
  •  旧巷少年郎
    2020-11-29 10:32

    Check this workaround: https://stackoverflow.com/a/43881141

    If you don’t control the server your frontend JavaScript code is sending a request to, and the problem with the response from that server is just the lack of the necessary Access-Control-Allow-Origin header, you can still get things to work—by making the request through a CORS proxy.

    In short, prefix the request so the full URI looks something like this:

    https://cors-anywhere.herokuapp.com/https://api.twitter.com/oauth/request_token
    

    Unfortunately, you will not be able to use most Twitter libraries this way, but you can continue using fetch with the cors-anywhere prefix.

提交回复
热议问题