【问题标题】:Calling Twitter API results in "Timestamp out of bounds" Error调用 Twitter API 导致“时间戳越界”错误
【发布时间】:2018-09-01 17:50:23
【问题描述】:

我正在致电 Twitter 以获取用户时间线详细信息。这是我的代码

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: OAuth oauth_consumer_key=\"XXXXXXX\",oauth_token=\"XXXXXXX\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"XXXXXXX\",oauth_nonce=\"XXXXXXXX\",oauth_version=\"1.0\",oauth_signature=\"XXXXXXX\"",
      "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}    

我可以获取详细信息。但是一天后我收到了这个回复

{"errors":[{"code":135,"message":"Timestamp out of bounds."}]}

我的令牌会过期吗?我想将此代码作为后台请求运行。

【问题讨论】:

  • 这个问题一般是因为 timestamp ,你为 oauth_timestamp 设置的
  • 我使用 Post Man 生成当前时间戳,即 1521786006

标签: twitter oauth postman twitter-oauth


【解决方案1】:

oauth_timestamp 应该是自 1970 年 1 月 1 日 00:00:00 UTC 以来的整秒数。

{"errors":[{"code":135,"message":"Timestamp out of bounds."}]}

通常意味着您的服务器/机器时间关闭超过 30 秒(实际时间不包括时区差异)。查看响应标头以了解 Twitter 的时间。

oauth_timestamp=1521786006

【讨论】:

  • 我的服务器时间已同步并显示正确时间。在响应标头中,GMT 时间是必须的。我错过了什么吗?
猜你喜欢
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-28
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多