php - 推特 1.1 OAuth authenticity_token_error(99)

标签 php curl twitter-oauth

我使用以下代码获取不记名 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":"Unable to verify your credentials"}]}

我做错了什么?

最佳答案

在解决这个问题一段时间后,我发现问题是我正在使用 Advanced Rest Client 从我已经登录 Twitter 的浏览器调用/oauth2/token。注销 Twitter 并再次调用 API 后,一切正常。

简短回答:确保您在尝试请求 Bearer token 时还没有登录到 Twitter 的事件 session 。

关于php - 推特 1.1 OAuth authenticity_token_error(99),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23183050/

相关文章:

ios - 白名单推特登录仍然收不到邮件

android - 使用 twitter4j 登录

php - 如何将查询字符串值传递到通过 AJAX 加载的页面?

PHP自定义错误页面

php - mysql数据库中的HTML标签?

java - Spring Boot POST 请求特定负载不被接受

google-app-engine - 属性错误 : 'NoneType' object has no attribute 'wrap_socket' in GAE

PHP echo 错误值

php - PHP 中缺少一些 CURL 常量

php - php 中的 Soap 版本不匹配