Twitter 1.1 OAuth authenticity_token_error(99) [英] Twitter 1.1 OAuth authenticity_token_error(99)
问题描述
我使用以下代码获取承载令牌:
I use the following code to get the bearer token:
$token = base64_encode($client_id.':'.$client_sec);
$data = array ('grant_type' => 'client_credentials');
$data = http_build_query($data);
$header = array(
'Authorization: Basic '.$token,
'Content-type: application/x-www-form-urlencoded;charset=UTF-8',
'Content-Length: ' . strlen($data)
);
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => 'https://api.twitter.com/oauth2/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
exit;
但所有时间输出:
{errors:[{label:authenticity_token_error,code:99,message:无法验证您的凭据}]}
{"errors":[{"label":"authenticity_token_error","code":99,"message":"Unable to verify your credentials"}]}
我做错了什么?
推荐答案
在与这个问题战斗了一段时间后,我发现问题是我使用高级Rest客户端从/ oauth2 /令牌调用从我已经登录到Twitter的浏览器。在注销Twitter并再次调用API后,它工作正常。
After fighting with this problem for a while I found the problem was I was making the call to /oauth2/token using Advanced Rest Client from a browser I was already logged into Twitter with. After logging out of Twitter and making the API call again it worked fine.
简短答案:请确保您在尝试请求承载令牌时尚未登录Twitter。
Short answer: make sure you do not already have an active session logged into Twitter when attempting to request a Bearer token.
这篇关于Twitter 1.1 OAuth authenticity_token_error(99)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!