Skip to content

Commit

Permalink
docs: use blogger to demonstrate key authentication (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Cervino authored and JustinBeckwith committed Jan 2, 2019
1 parent f6edb8e commit 438979a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions README.md
Expand Up @@ -144,9 +144,9 @@ const oauth2Client = new google.auth.OAuth2(
YOUR_REDIRECT_URL
);

// generate a url that asks permissions for Google+ and Google Calendar scopes
// generate a url that asks permissions for Blogger and Google Calendar scopes
const scopes = [
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/blogger',
'https://www.googleapis.com/auth/calendar'
];

Expand Down Expand Up @@ -204,18 +204,22 @@ oauth2client.setCredentials({
Once the client has a refresh token, access tokens will be acquired and refreshed automatically in the next call to the API.

### Using API keys
You may need to send an API key with the request you are going to make. The following uses an API key to make a request to the Google+ API service to retrieve a person's profile given a userId:
You may need to send an API key with the request you are going to make. The following uses an API key to make a request to the Blogger API service to retrieve a blog's name, url, and its total amount of posts:

``` js
const {google} = require('googleapis');
const plus = google.plus({
version: 'v1',
const blogger = google.blogger_v3({
version: 'v3',
auth: 'YOUR_API_KEY' // specify your API key here
});

async function main() {
const res = await plus.people.get({ userId: 'me' });
console.log(`Hello ${res.data.displayName}!`);
const params = {
blogId: 3213900
};

async function main(params) {
const res = await blogger.blogs.get({blogId: params.blogId});
console.log(`${res.data.name} has ${res.data.posts.totalItems} posts! The blog url is ${res.data.url}`)
};

main().catch(console.error);
Expand Down

0 comments on commit 438979a

Please sign in to comment.