首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twitch API -请求身份验证令牌不返回任何内容

Twitch API -请求身份验证令牌不返回任何内容
EN

Stack Overflow用户
提问于 2014-07-24 20:15:51
回答 1查看 471关注 0票数 0

我也有类似的问题:Twitch API - can't get auth token using PHP,但不能写评论。

已尝试执行以下代码:

代码语言:javascript
复制
    $ch = curl_init("https://api.twitch.tv/kraken/oauth2/token");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$fields = array(
    'client_id' => 'blablabla_correct',
    'client_secret' => 'blablabla_also_correct',
    'grant_type' => 'authorization_code',
    'redirect_uri' => 'http://localhost/php/twitch.php',
    'code' => $_GET['code']
);


 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    $data = curl_exec($ch);
print $data;

但它什么也不打印。因此,我尝试使用#2中的代码来调试请求:

代码语言:javascript
复制
// to start, just use the code you've already got:
$ch = curl_init("https://api.twitch.tv/kraken/oauth2/token");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$fields = array(
    'client_id' => 'blablabla_correct',
    'client_secret' => 'blablabla_also_correct',
    'grant_type' => 'authorization_code',
    'redirect_uri' => 'http://localhost/php/twitch.php',
    'code' => $_GET['code']
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$data = curl_exec($ch);

// Now, here we believe the first error comes into play, so let's check it out
print_r($data); // confirm that this is not what we want
$info = curl_getinfo($ch); // let's get some details about that last request
// print it out and see what we get
echo '<pre>';
print_r($info);
echo '</pre>';

然后我跟随数组。我不知道下一步该怎么办。API文档在这里:https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code

代码语言:javascript
复制
Array
(
    [url] => https://api.twitch.tv/kraken/oauth2/token
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.203
    [namelookup_time] => 0
    [connect_time] => 0.203
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 192.16.71.172
    [primary_port] => 443
    [local_ip] => 192.168.1.100
    [local_port] => 51603
    [redirect_url] => 
)
EN

回答 1

Stack Overflow用户

发布于 2014-07-24 20:32:34

我可能是错的,但作为其他登录提供商,我可以想象twitch也不允许redirect urls访问像localhost这样的非现有域名。

如果你想让localhost返回urls,我更喜欢这个服务,你可以把你的重定向url指向一个通配符服务器,然后请求被重定向到你的localhost。

http://xip.io

xip.io是一个魔术域名,它为任何IP地址提供通配符DNS。假设您的LAN IP地址是10.0.0.1。使用xip.io,

10.0.0.1.xip.io解析为10.0.0.1 www.10.0.0.1.xip.io解析为10.0.0.1 mysite.10.0.0.1.xip.io解析为10.0.0.1 foo.bar.10.0.0.1.xip.io解析为10.0.0.1

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24933438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档