Reputation: 7629
How to setup a google project api key.i want to use google directory apis. and have to retrieve user's list in the domain.In google Api explorer(https://developers.google.com/apis-explorer/#p/admin/directory_v1/directory.users.list) i authorized and get the list of all users in my domain.but when i use node.js for retrieving the users's list in response i am getting
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
here is small snippet of node.js code
var request = require('request');
var request1 = {url : 'https://www.googleapis.com/admin/directory/v1/users',
headers :{'Authorization' : 'Bearer '+bodyy.access_token},query:{
domain : 'iritesh.com',key:'AIzaSyBrTEYAap74npiUhKWGp0eLcPY1kBMnTIk'
},method : 'GET'};
request(request1,function(err,ress,body){
console.log('body is');
console.log(body);
res.render('index',{title: 'Express'});
});
i doubt i am getting this error because i didn't set up public key properly.my system ip address is 103.245.XX.XX and i have setup same IP address in Project console.can anyone please guideline what should i fill in allowed Server IP addresses when i am using localhost.am i doing any mistake??i enabled API Access in Admin Console also.my system admin is [email protected] and domain is iritesh.com.temporarily i hardcoded it,please ignore this.i am attaching snapshot related to that.
Upvotes: 1
Views: 898
Reputation: 43
It looks like you have a syntax error in your code:
bodyy.access_token
should maybe be?
body.access_token
Upvotes: 0
Reputation: 116908
for starters Users: list requires authorization which means you will need to use Open authentication and not a public API key.
Documentation for users: list
Users: list
Requires authorization
Answer: your code doesn't work because you are trying to use a public api key with a API that requires Authentication.
Upvotes: 1