Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Vimeo API with generated AccessToken #21

Closed
throrin19 opened this issue Mar 19, 2015 · 4 comments
Closed

Request Vimeo API with generated AccessToken #21

throrin19 opened this issue Mar 19, 2015 · 4 comments

Comments

@throrin19
Copy link

Hi, i've try to use your library to request vimeo API and get specific channel videos.

this is my code :

var vimeo = new Vimeo(settings.vimeo.client_id, settings.vimeo.client_secret, settings.vimeo.access_token);
vimeo.request({
    path : 'channels/'+params.channel_id + '/videos',
    query : {
        sort        : 'date',
        direction   : 'desc'
    }
}, function (err, res) {
    if (err) {
        return callback(err);
    }
    callback(null, res);
});

If I try this code, i get this error on nodeJS :

Error: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

    at IncomingMessage.<anonymous> (/home/throrin19/Development/Web/goomeoeventsapi/node_modules/vimeo-api/lib/vimeo.js:152:15)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16
    at process._tickDomainCallback (node.js:463:13)

I decide to test this request on postman and it works.

What is wrong ?

@Dashron
Copy link
Contributor

Dashron commented Mar 19, 2015

Which channel id are you using?

@throrin19
Copy link
Author

For this example i use the staffpicks channel. But why it works fine in postman and don't works with this library ?

The problem is in your library, i request directly the api with the request module and it works fine :

request({
    url : 'https://api.vimeo.com/channels/'+params.channel_id + '/videos',
    qs : {
        sort        : 'date',
        direction   : 'desc'
    },
    headers : {
        'Authorization' : 'Bearer ' + settings.vimeo.access_token
    },
    json : true
}, function (err, res, body) {
    if (err) {
        return callback(err);
    }
    if(res.statusCode !== 200){
        return callback(new Error('Vimeo API return an error : ' + res.statusCode));
    }
    callback(null, body);
});

@Dashron
Copy link
Contributor

Dashron commented Mar 23, 2015

Path must contain the leading forward slash, otherwise it loads api.vimeo.comchannels/staffpicks/videos. Your code should look like the following:

var vimeo = new Vimeo(settings.vimeo.client_id, settings.vimeo.client_secret, settings.vimeo.access_token);
vimeo.request({
    path : '/channels/'+params.channel_id + '/videos',
    query : {
        sort        : 'date',
        direction   : 'desc'
    }
}, function (err, res) {
    if (err) {
        return callback(err);
    }
    callback(null, res);
});

I'll make a note to check for this in our next release

@throrin19
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants