How to get eventbrite access token returned with response?

55 views
Skip to first unread message

sultan26

unread,
Jun 28, 2017, 8:56:41 AM6/28/17
to Eventbrite API
I am trying to authenticate a user using eventbrite APIs The code I am using is

var url = require('url');
   
var url_parts = url.parse(req.url, true);
   
var query = url_parts.query;
   
var _code = query.code;        
   
var url = constant.OAUTH_URL
   
var request = require('request');
   
var querystring = require('querystring');


   
var form = {
        code
: _code,
        client_secret
: constant.CLIENT_SECRET,
        client_id
: constant.CLIENT_SECRET,
        grant_type
: 'authorization_code'
   
};


   
var formData = querystring.stringify(form);
   
var contentLength = formData.length;
    request
({
        headers
: {
           
'Content-Length': contentLength,
           
'Content-Type': 'application/x-www-form-urlencoded'
       
},
        uri
: url,
        body
: formData,
        method
: 'POST'
   
}, function (err, resp, body) {          
       
//Here I want to access the access token from response.
   
});

There is no error in code. The issue is eventbrite redirects to the URL configured in the console. If this could have been done on local machine, I would have taken 'resp' or 'body' object and scanned it for the access token but the page is located at external location and console.log() doesn't work either. Where does eventbrite return access token? Body? Headers? or In an object with response? How can I get that?

Barrett Cook

unread,
Jun 28, 2017, 6:12:57 PM6/28/17
to Eventbrite API
It looks like you're sending the CLIENT_SECRET as both the client_secret and the client_id parameters. The client_id should be the same you used for the original redirect when asking the user to authorize your app.

sultan26

unread,
Jun 30, 2017, 9:41:16 AM6/30/17
to Eventbrite API
Sorry for replying late Barrett. The above code was modified before posting to not expose the actual values. The issue was that the response returned by the API was on a "hosted" page. I could not use the local code(written above) as after authentication the users are redirected to the apps URL specified in the console and the above code was on my local machine. So I didn't have any idea about the response format, like was it in body or headers? I had to manually print the response and body and then I came to know the response is returned like:
{
"access_token": "value",
"type": "Bearer"
}

Maybe I missed it in the documentation or it is not there or it's just my bad I didn't dig into the response. Anyways, thanks for your help.
Reply all
Reply to author
Forward
0 new messages