Twitter 1.1 OAuth authenticity_token_error(99)

后端 未结 4 1140
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 04:41

I use the following code to get the bearer token:

$token = base64_encode($client_id.\':\'.$client_sec);

$data = array (\'grant_type\' => \'client_credent         


        
4条回答
  •  青春惊慌失措
    2020-12-19 04:55

    After fighting with this problem, i finally come up with the solution. Twitter is not actually sending the right message if error exist anywhere.

    When i send request from curl, it works fine but when through code. i was having same error {"errors":[{"label":"authenticity_token_error","code":99,"message":"Unable to verify your credentials"}]}

    So what i got, problem was lying with Access control header. setting these header does not work for me

         xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
         xhttp.setRequestHeader('Access-Control-Allow-Headers', '*');
         xhttp.setRequestHeader('Access-Control-Allow-Origin', '*')
         xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
    

    as a workaround i just used this url to bypass request to handler cors

    https://cors-anywhere.herokuapp.com/https://api.twitter.com/oauth2/token
    

    added "https://cors-anywhere.herokuapp.com/" before the actual url and it began to work. hope someone may face this issue in problem

提交回复
热议问题