【问题标题】:Twitter returns strange data for auth-only appTwitter为仅授权应用返回奇怪的数据
【发布时间】:2014-01-09 09:53:08
【问题描述】:

我用这个代码

define('CONSUMER_KEY', 'X________________w');
define('CONSUMER_SECRET', 'k_______________________________A');
$encodedAccessToken = base64_encode(urlencode(CONSUMER_KEY).':'.urlencode(CONSUMER_SECRET));
$options = array(
"https" => array(
    "method" => "POST",
    "header" => "Host: api.twitter.com\n".
                 "User-agent: orlec_test v1.0.23\n".
                 "Authorization: Basic ".$encodedAccessToken."\n".
                 "Content-Type: application/x-www-form-urlencoded;charset=UTF-8\n".
                 "Content-Length: 29\n".
                 "Accept-Encoding: gzip\n",
    "content" => "grant_type=client_credentials"
),
);
$url = "https://api.twitter.com/oauth2/token";
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;

如果在 $options 数组中使用“http”而不是 twitter 回复我:

ЋV*ЩЯNЭ/Љ,HUВRJJM,J-RвQJLNN-.KХБДаt+й ;д%ЪЗиЛТЌ бйТг5аЕАЂЪв7Џ$[еиХ7'8е9АРЫ5%8Ф%ЅАЪбЬа45 Ъ198ЂТФиЗ8/М(Г,2-ийХЧФШлаЯ+LЉэќ(

否则,如果我使用“https”推特返回

Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in C:\xampp\htdocs\index3.php on line 19

我做错了什么?

【问题讨论】:

    标签: php authentication twitter


    【解决方案1】:

    这是仅应用身份验证的工作示例:https://gist.github.com/lgladdy/5141615

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2016-12-24
      • 2016-05-31
      • 1970-01-01
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多