Eventbrite API 简单访问令牌请求不起作用


Eventbrite API simple access token request doesn't work

我的代码实际上可以完美地与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 请求失败!HTTP/1.1 400 错误请求在/var/www/include/actions.php 第 102 行

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


更新:

我终于找到了问题所在(即使我不明白为什么):

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);    

我希望它能帮助任何遇到相同问题的人;)

为了让这个问题不会继续在自动电子邮件中显示为未回答,我将在此处添加您的更新中的答案 - 希望它已经点燃!

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);

感谢您通过回答您自己的问题来简化它! ;)