rubenCodeforges / ng-gapi

ng-gapi a Google api module for Angular 6+
127 stars 42 forks source link

Need to get G-Suite contact #95

Closed chetanganguly closed 4 years ago

chetanganguly commented 4 years ago

Hi Is this ng-gapi used for G-Suite login and fetching importing contact list ? I'm not seeing apiKey in configuration..is apiKey not needed for calling contact api for G suite user. i want to call "https://www.googleapis.com/admin/directory/v1/users" but not able to do it getting 400. i'm following this url.."https://stackblitz.com/edit/ng-gapi-example" login working fine but when i try to get users list getting 400.

-----Service code ------ private readonly API_URL: string = "https://www.googleapis.com/admin/directory/v1/users"; constructor( private _http: HttpClient, private _apiServe: ApiService, private googleAuthService: GoogleAuthService, private ngZone: NgZone ) {} // ------------------------- public signIn() { this.googleAuthService.getAuth().subscribe(auth => { auth .signIn() .then( res => this.signInSuccessHandler(res), err => this.signInErrorHandler(err) ); }); } private signInSuccessHandler(res: GoogleUser) { this.ngZone.run(() => { debugger; this.user = res; sessionStorage.setItem( GSuiteService.SESSION_STORAGE_KEY, res.getAuthResponse().access_token );

  this.importContact(this.getToken()).subscribe(
    res => {
      debugger;
    },
    error => {
      debugger;
    }
  );
});

} // authtoken as parameter only for demo purpose , better use a UserService to get the token public importContact(authtoken: string): Observable { return this._http.get( this.API_URL, { headers: new HttpHeaders({ Authorization: Bearer ${authtoken} }) } ); } private signInErrorHandler(err) { debugger; console.warn(err); } public getToken(): string { let token: string = sessionStorage.getItem( GSuiteService.SESSION_STORAGE_KEY ); if (!token) { throw new Error("no token set , authentication required"); } return sessionStorage.getItem(GSuiteService.SESSION_STORAGE_KEY); } Thanks Chetan

rubenCodeforges commented 4 years ago

@chetanganguly hi , try to change the client_id

chetanganguly commented 4 years ago

@chetanganguly hi , try to change the client_id

Hi @rubenCodeforges Thanks for you quick reply . I had created client_id using G-suite login credential and its working fine for g suite user . issue only after try to get user list (https://www.googleapis.com/admin/directory/v1/users). Not sure domain and apiKey need to pass as parameter or not. Here is my app module config let gapiClientConfig: NgGapiClientConfig = { client_id: "client_id", discoveryDocs: [ "https://analyticsreporting.googleapis.com/$discovery/rest?version=v4" ], scope: [ "https://www.googleapis.com/auth/admin.directory.user.readonly", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/admin.directory.user" ].join(" ") };

please let me know if anything. Its urgent Regards chetan

rubenCodeforges commented 4 years ago

@chetanganguly sorry its hard to tell , since i dont get whats the issue is