1 | ;
|
2 | /**
|
3 | * Copyright 2013 Vimeo
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 |
|
18 | var Vimeo = require('../index').Vimeo;
|
19 |
|
20 | try {
|
21 | var config = require('./config.json');
|
22 | } catch (error) {
|
23 | console.error('ERROR: For this example to run properly you must create an api app at developer.vimeo.com/apps/new and set your callback url to http://localhost:8080/oauth_callback');
|
24 | console.error('ERROR: Once you have your app, make a copy of config.json.example named "config.json" and add your client id, client secret and access token');
|
25 | return;
|
26 | }
|
27 |
|
28 | // Here we have to build the vimeo library using the client_id, client_secret and an access token
|
29 | // For the request we make below (/channels) the access token can be a client access token instead of a user access token.
|
30 | var lib = new Vimeo(config.client_id, config.client_secret);
|
31 |
|
32 | if (config.access_token) {
|
33 | lib.access_token = config.access_token;
|
34 | makeRequest(lib);
|
35 | } else {
|
36 | // Unauthenticated api requests must request an access token. You should not request a new access token for each request, you should request an access token once and use it over and over.
|
37 | lib.generateClientCredentials('public', function (err, access_token) {
|
38 | if (err) {
|
39 | throw err;
|
40 | }
|
41 |
|
42 | // Assign the access token to the library
|
43 | lib.access_token = access_token.access_token;
|
44 | makeRequest(lib);
|
45 |
|
46 | });
|
47 | }
|
48 |
|
49 |
|
50 | function makeRequest(lib) {
|
51 | // Make an API request
|
52 | lib.request({
|
53 | // This is the path for the videos contained within the staff picks channels
|
54 | path : '/me/videos',
|
55 | query : {
|
56 | per_page : 1
|
57 | }
|
58 | }, function (error, body, status_code, headers) {
|
59 | if (error) {
|
60 | console.log('error');
|
61 | console.log(error);
|
62 | } else {
|
63 | console.log('body');
|
64 | console.log(body);
|
65 | }
|
66 |
|
67 | console.log('status code');
|
68 | console.log(status_code);
|
69 | console.log('headers');
|
70 | console.log(headers);
|
71 | });
|
72 | }
|