【问题标题】:Eventbrite API simple access token request doesn't workEventbrite API 简单访问令牌请求不起作用
【发布时间】:2013-10-21 11:18:04
【问题描述】:

我的代码实际上与 Linkedin 和 Meetup API 完美配合,但不适用于 Eventbrite API,我绝对不明白为什么:

$params = array(
                        'grant_type' => 'authorization_code',
                        'client_id' => EVENTBRITE_CONSUMER_KEY,
                        'client_secret' => EVENTBRITE_CONSUMER_SECRET,
                    );

// Eventbrite API access token request
$url = 'https://www.eventbrite.com/oauth/token?' . http_build_query($params);

// Tell streams to make a POST request
$context = stream_context_create(array('http' => array('method' => 'POST')));

// Retrieve access token information
$response = file_get_contents($url, false, $context);

我认为获取授权码的 API 登录部分似乎运行良好。

这是 PHP 错误:

警告:file_get_contents(https://www.eventbrite.com/oauth/token?grant_type=authorization_code&client_id=ZZ6PPQOMTKSXIHEKLR&client_secret=QQDDIS4RBZXI6ONO7QEYEUZ4JB2ABQQG6K3H7CBD6M5QWK5GSK&code=O63YZASRAYMOUHRMH5AH):打开流失败:HTTP 请求失败! /var/www/include/actions.php 第 102 行中的 HTTP/1.1 400 BAD REQUEST

如果有人有线索,请提前感谢:)


更新:

我终于发现问题出在哪里(即使我不明白为什么):

file_get_contents 似乎不是访问 oauth 页面的好方法,我使用 curl 代替:

$request_url = 'https://www.eventbrite.com/oauth/token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);    

希望对遇到同样问题的人有所帮助;)

【问题讨论】:

  • 那是因为它响应的是参数而不是数据。

标签: php api oauth oauth-2.0 eventbrite


【解决方案1】:

为了让这个问题不会继续在自动电子邮件中显示为未回答,我将在此处添加您从更新中获得的答案 - 希望一切顺利!

file_get_contents 似乎不是访问 oauth 页面的好方法,我使用 curl 代替:

$request_url = 'https://www.eventbrite.com/oauth/token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);

感谢您通过回答您自己的问题来轻松解决问题! ;)

【讨论】:

    猜你喜欢
    • 2016-05-23
    • 2013-02-17
    • 1970-01-01
    • 2017-12-30
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    相关资源
    最近更新 更多