은승우

Update app.js

Showing 1 changed file with 23 additions and 10 deletions
...@@ -64,19 +64,29 @@ const client = new line.Client(config); ...@@ -64,19 +64,29 @@ const client = new line.Client(config);
64 const vision = require('@google-cloud/vision'); 64 const vision = require('@google-cloud/vision');
65 65
66 // Creates a client 66 // Creates a client
67 -const visionclient = new vision.ImageAnnotatorClient(); 67 +var vision = require('google-vision-api-client');
68 68
69 -/** 69 +var requtil = vision.requtil;
70 - * TODO(developer): Uncomment the following line before running the sample.
71 - */
72 -// const fileName = 'Local image file, e.g. /path/to/image.png';
73 70
74 -// Performs text detection on the local file
75 -const [result] = visionclient.textDetection('/home/ubuntu/a/LINEBOT/photo/Fancy-TWICE.jpg');
76 -const detections = result.textAnnotations;
77 -console.log('Text:');
78 -detections.forEach(text => console.log(text));
79 71
72 +
73 +//Prepare your service account from trust preview certificated project
74 +
75 +var jsonfile = '/Users/terry/dev/ws/nodejs/GoogleVisionAPISample/My Project-eee0a2d4532a.json';
76 +
77 +
78 +
79 +//Initialize the api
80 +
81 +vision.init(jsonfile);
82 +
83 +
84 +
85 +//Build the request payloads
86 +var d = requtil.createRequests().addRequest(
87 +requtil.createRequest('/Users/terry/images/dale2.jpg')
88 +.withFeature('Optical Character Recognition', 3)
89 +.build());
80 //Do query to the api server 90 //Do query to the api server
81 vision.query(d, function(e, r, d){ 91 vision.query(d, function(e, r, d){
82 if(e) console.log('ERROR:', e); 92 if(e) console.log('ERROR:', e);
...@@ -85,6 +95,9 @@ if(e) console.log('ERROR:', e); ...@@ -85,6 +95,9 @@ if(e) console.log('ERROR:', e);
85 95
86 96
87 97
98 +
99 +
100 +
88 app.post('/webhook', line.middleware(config), (req, res) => { 101 app.post('/webhook', line.middleware(config), (req, res) => {
89 Promise 102 Promise
90 .all(req.body.events.map(handleEvent)) 103 .all(req.body.events.map(handleEvent))
......