Question

My code, which actually perfectly works with Linkedin and Meetup APIs, doesn't work with Eventbrite API and I definitely don't understand why :

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

I precise that the API login part to get the authorization code seems to work perfectly well.

Here is the PHP error :

Warning: file_get_contents(https://www.eventbrite.com/oauth/token?grant_type=authorization_code&client_id=ZZ6PPQOMTKSXIHEKLR&client_secret=QQDDIS4RBZXI6ONO7QEYEUZ4JB2ABQQG6K3H7CBD6M5QWK5GSK&code=O63YZASRAYMOUHRMH5AH): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD REQUEST in /var/www/include/actions.php on line 102

Thanks by advance if anybody has a clue :)


UPDATE :

I finally found where is the problem (even if I don't understand why) :

file_get_contents doesn't seem to be a good method to access the oauth page, I used curl instead :

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

I hope it will help anybody encountering the same issue ;)

Était-ce utile?

La solution

Just so that this question doesn't continue to show up as unanswered in an auto-email, I'm going to add your answer from your update here -- hope that's alight!

file_get_contents doesn't seem to be a good method to access the oauth page, I used curl instead:

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

Thanks for making it easy by answering your own question! ;)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top