설치하다
이 라이브러리는 NPM을 통해 게시됩니다. 다음 명령을 통해 Googleapis 및 그 종속성을 설치하십시오
$ npm 설치 GOOGLEAPIS
API 지원 목록 https://developers.google.com/apis-explorer
사용
예 1 : Google 짧은 주소를 통해 전체 주소 받기
var google = require ( 'googleapis'); var urlshortener = google.urlshortener ( 'v1'); var params = {shorturl : 'http://goo.gl/xkbru3'}; // 단축 URL URLSHORTENE.URL.GET (params, function (err, response) {console.log ( 'long url is', response.longurl);}의 긴 URL을 가져옵니다.예 2 : 로그인 인증
이 예제는 OAUTH2 인증을 통합하여 사용자에게 액세스 하고이 토큰을 새로 고칠 수 있도록 세션이 만료되는 것을 방지 할 수 있습니다.
var google = require ( 'googleapis'); var plus = google.plus ( 'v1'); var oauth2client = new Oauth2 (client_id, client_secret, redirect_url); // 위에서 설명한 토큰 교환을 통해 토큰 검색을 검색하거나 설정하십시오. OAuth2Client.setCredentials ({access_token : 'access token here', refresh_token : '새로 고침 토큰'}); plus.people.get ({userId : 'me', auth : oauth2client}, function (err, response) {// hrong and response});전체 로그인 승인 예. https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js
예 3 : 파일 업로드
var fs = 요구 ( 'fs'); var drive = google.drive ({버전 : 'v2', auth : oauth2client}); drive.files.insert ({resource : {title : 'testimage.png', mimetype : 'image/png'}, media : {mimetype : 'image/png', body : fs.createreadstream ( 'savice.png') // 읽기 스트림}}, 호출);질문 답변?
궁금한 점이 있으면 stackoverflow로 가서 물어보십시오.
취약점을 찾으면 Github에서 문제를 제출할 수 있습니다.