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

时间:2013-10-21 11:18:05

标签: php api oauth oauth-2.0 eventbrite

我的代码实际上与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请求失败!第102行/var/www/include/actions.php中的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);    

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

1 个答案:

答案 0 :(得分:2)

为了让这个问题不会在自动电子邮件中继续显示为无人问津,我将在此处添加您的更新答案 - 希望它能够点亮!

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

感谢您通过回答自己的问题轻松实现! ;)