2016年11月17日 星期四

line notify 每個人拿到的access token 不同,故可以拿來做區分!

import https = require("https");
import express = require("express");
import bodyParser = require('body-parser');
import request = require("request");
let app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());

app.get("/", (req, res) => {
    res.end("home")
})

app.post('/callback',function(request,response){
   console.log(request.body.code) //you will get your data in this as object.
   console.log(request.body.state) //you will get your data in this as object.
 
   response.end("ok")
})
app.listen(3000);


//1.get code
//https://notify-bot.line.me/oauth/authorize?client_id=...&response_type=code&redirect_uri=https://030b4fae.ngrok.io/callback&scope=notify&state=good&response_mode=form_post
//

//2.get access tokken
// var formData = {
//     grant_type : "authorization_code",
//     code : "...",
//     redirect_uri : "https://030b4fae.ngrok.io/callback",
//     client_id : "....",
//     client_secret : "..."
// }
// request.post({
//     url:"https://notify-bot.line.me/oauth/token",
//     formData  : formData
// },

// (err, httpResponse, body)=>{
//     // console.log(err);
 
//     // console.log(httpResponse);
 
//     console.log(body);
 
// });

3. send message

request.post({
    url:"https://notify-api.line.me/api/notify",
    headers : {
"Content-Type":"application/x-www-form-urlencoded",
    "Authorization" : "Bearer ..."
    },
    formData: {
            message :"Hello Bady"
        }
    },

(err, httpResponse, body)=>{
 
    console.log(body);
 
}


https://notify-bot.line.me/my/services/

沒有留言:

張貼留言