Giter Site home page Giter Site logo

apis-101's Introduction

apis-101

This repo is for experimenting with APIs.

Follow the steps below to set up a simple Node.js command-line application that makes requests to the YouTube Data API. ๐Ÿš€

Prerequisites

To run this project, you'll need:

  • Node.js installed.
  • The npm package management tool (comes with Node.js).
  • Access to the internet and a web browser.
  • A Google account.

Setup

Here are some steps to get the project running locally:

  1. Clone the repo -> run git clone [email protected]:alex-blair/apis-101.git in the command line.

  2. Run npm install.

  3. Next you'll need to obtain authorization credentials so your application can submit API requests. Follow the steps here under "Step 1: Turn on the YouTube Data API".

  4. Once you've got your client_secret.json (see the link in the step above), go to the command line and run node quickstart.js. The first time you run this, it will prompt you to authorize access:

    • Navigate to the URL provided in the command line using your web browser.

    • If you are not already logged into your Google account, you will be prompted to log in. If you are logged into multiple Google accounts, you will be asked to select one account to use for the authorization.

    • Click the Accept button.

    • Copy the code you're given, paste it into the command-line prompt, and press Enter.

    • You should see the following printed in the console:

    This channel's ID is UC_x5XG1OV2P6uZZ5FSM9Ttw. Its title is 'Google Developers', and it has xxxxxxx views.
    

    If you can see this - congrats!! ๐ŸŽ‰ The hardest part is over!

    You can now test requesting information about different channels by editing the getChannel function.

    You can find a list of data related to a channel here.

    For instance, you could try requesting the description from GoogleDevelopers by adding channels[0].snippet.description to the console.log.

    Deeper Dive

If you want to try out some of the other API requests in src, you'll need to do a bit more setup:

  1. Find out where youtube-nodejs-quickstart.json has been saved locally and add a copy of it to your project file. Rename it youtube_token.json in your project.
    • Tip: You can see where youtube-nodejs-quickstart.json was saved by logging TOKEN_PATH i.e. add the following line to quickstart.js:
var TOKEN_PATH = TOKEN_DIR + 'youtube-nodejs-quickstart.json'
console.log('Location of token: ' + TOKEN_PATH ) // Add this line

Then run node quickstart.js. The location of the token should be printed in the console ๐Ÿ˜„

  1. Once you have the token saved as youtube_token.json in your project, you can use it to run the functions in search1.js, search2.js, search3.js (this project was originally set up for a demo, so you'll notice there's a bit of code duplication ยฏ_(ใƒ„)_/ยฏ ).

โš ๏ธImportant note: Make sure not to upload your client_secret.json or youtube_toke.json to Github! In this project both files are listed in the .gitignore, so by default will not be added when you make a commit. However, if you rename either of these files, remember to update the .gitignore so that you don't commit them by mistake. They contain secrets, and should not be made public on Github.โš ๏ธ

apis-101's People

Contributors

alex-blair avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.