|
@@ -1,150 +1,4 @@
|
|
|
-// // curl -X POST https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code={authorization_code_from_step2_response}&redirect_uri={your_callback_url}&client_id={your_client_id}&client_secret={your_client_secret}' \
|
|
|
-// // -H 'Content-Type: application/x-www-form-urlencoded'
|
|
|
-
|
|
|
-// const express = require('express');
|
|
|
-// const mail = require('./notification.js')
|
|
|
-
|
|
|
-// let axios = require('axios')
|
|
|
-// const app = express();
|
|
|
-
|
|
|
-// if (process.env.usermail) mail.notif(process.env.usermail, process.env.pswd, process.env.contact);
|
|
|
-
|
|
|
-// let info = {
|
|
|
-// followers: 0000,
|
|
|
-// companyID: null,
|
|
|
-// orgaName: "spirit_3",
|
|
|
-// appID: "86wenleyh4u42g",
|
|
|
-// secret: "CCv35kAHKCuXFqEX",
|
|
|
-// scope :[
|
|
|
-// 'r_emailaddress', 'r_liteprofile', 'r_1st_connections_size', 'rw_organization_admin'
|
|
|
-// ],
|
|
|
-// tokens: {
|
|
|
-// access_token: "",
|
|
|
-// expires_in: 23444
|
|
|
-// },
|
|
|
-// active: false,
|
|
|
-// updateTime: 2 * 60000 // 2min
|
|
|
-// }
|
|
|
-
|
|
|
-// if (process.env.access_token) {
|
|
|
-// info.tokens.access_token = process.env.access_token
|
|
|
-// info.active = true
|
|
|
-// }
|
|
|
-// if (process.env.expire) info.tokens.expires_in = process.env.expire
|
|
|
-
|
|
|
-// const bodyParameters = {
|
|
|
-// key: "Content-Type",
|
|
|
-// value: "application/json"
|
|
|
-// };
|
|
|
-
|
|
|
-// console.log("process env TOKEN =>", process.env.access_token);
|
|
|
-// console.log("process env expire =>", process.env.expire);
|
|
|
-
|
|
|
-// var Linkedin = require('node-linkedin')(info.appID, info.secret, info.tokens.access_token);
|
|
|
-
|
|
|
-// async function linkedinApiRequest(url){
|
|
|
-// axios.post(url,
|
|
|
-// bodyParameters,
|
|
|
-// {
|
|
|
-// headers: {
|
|
|
-// 'Authorization': 'Bearer ' + info.tokens.access_token,
|
|
|
-// 'cache-control': 'no-cache',
|
|
|
-// 'X-Restli-Protocol-Version': '2.0.0',
|
|
|
-// 'x-li-format': 'json'
|
|
|
-// },
|
|
|
-// })
|
|
|
-// .then(function (response) {
|
|
|
-// console.log(response);
|
|
|
-// return {"res": response, error: false}
|
|
|
-// })
|
|
|
-// .catch(function (error) {
|
|
|
-// console.log(error);
|
|
|
-// return {"res": response, "error": error}
|
|
|
-// });
|
|
|
-// }
|
|
|
-
|
|
|
-// function watchLinkedin(){
|
|
|
-// console.log("watchLinkedin function");
|
|
|
-// if (info.active && info.tokens.access_token){
|
|
|
-// // var linkedin = Linkedin.init();
|
|
|
-
|
|
|
-// if (!info.companyID){
|
|
|
-// // find the organisation ID
|
|
|
-// console.log("Try Request to get Company ID")
|
|
|
-// let testOrgaID = encodeURIComponent(`https://api.linkedin.com/v2/companySearch?q=search&query=${info.orgaName}`)
|
|
|
-// // let testOrgaID = `https://api.linkedin.com/v2/search?q=companiesV2&baseSearchParams.keywords=${info.orgaName}`
|
|
|
-// console.log(linkedinApiRequest(testOrgaID));
|
|
|
-// } else {
|
|
|
-// try {
|
|
|
-// let testorgaRoute = `https://api.linkedin.com/v2/organizations/${encodeURIComponent(info.companyID)}`
|
|
|
-// let networkRoute = `https://api.linkedin.com/v2/networkSizes/urn%3Ali%3Aorganization%3A${info.companyID}?edgeType=CompanyFollowedByMember`
|
|
|
-// console.log("test companies")
|
|
|
-// linkedinApiRequest(testorgaRoute)
|
|
|
-
|
|
|
-// } catch (error) {
|
|
|
-// console.log(error);
|
|
|
-// console.log("[Authorization Error] on getting company information")
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// setInterval(watchLinkedin, info.updateTime)
|
|
|
-// // watchLinkedin()
|
|
|
-
|
|
|
-
|
|
|
-// // --- --- --- Express Server
|
|
|
-
|
|
|
-// app.use(express.json());
|
|
|
-
|
|
|
-// app.get('/', (req, res) => {
|
|
|
-// res.json({number: info.followers})
|
|
|
-// });
|
|
|
-
|
|
|
-
|
|
|
-// app.post('/update', function (req, res) {
|
|
|
-// console.log(req.body.count ? req.body.count : "NO NUMBER !");
|
|
|
-// console.log("req.body ...");
|
|
|
-// let newNumber = req.body
|
|
|
-// console.log("newNumber", newNumber);
|
|
|
-// followers = newNumber.count
|
|
|
-// res.send({ info: `Got a POST request ${followers}`})
|
|
|
-// })
|
|
|
-
|
|
|
-
|
|
|
-// // --- --- Linkedin API access configuration
|
|
|
-
|
|
|
-// app.get('/oauth/linkedin', function(req, res) {
|
|
|
-// // set the callback url
|
|
|
-// let urlReq = req.protocol + '://' + req.headers.host + '/oauth/linkedin/callback'
|
|
|
-
|
|
|
-// console.log("urlReq", urlReq);
|
|
|
-// Linkedin.setCallback(urlReq);
|
|
|
-// Linkedin.auth.authorize(res, info.scope);
|
|
|
-// });
|
|
|
-
|
|
|
-// // Again, `res` is optional, you could pass `code` as the first parameter
|
|
|
-// app.get('/oauth/linkedin/callback', function(req, res) {
|
|
|
-// Linkedin.auth.getAccessToken(res, req.query.code, req.query.state, function(err, results) {
|
|
|
-// if ( err ) {
|
|
|
-// info.active = false
|
|
|
-// return console.log(err);
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log("[DEBUG] getAccessToken - result", results);
|
|
|
-// info.tokens = results
|
|
|
-// info.active = true
|
|
|
-
|
|
|
-// process.env.access_token = results.access_token
|
|
|
-// process.env.expire = results.expires_in
|
|
|
-// watchLinkedin()
|
|
|
-
|
|
|
-// return res.redirect('/');
|
|
|
-// });
|
|
|
-// });
|
|
|
-
|
|
|
-// console.log(`Listening on port :${process.env.PORT}`, );
|
|
|
-// app.listen(process.env.PORT);
|
|
|
+// Smiiirl Compteur - Entreprise Spirit SA
|
|
|
|
|
|
const path = require('path');
|
|
|
const express = require('express');
|
|
@@ -153,17 +7,36 @@ const port = process.env.PORT || 3000;
|
|
|
const bodyParser = require('body-parser');
|
|
|
const validator = require('validator');
|
|
|
const API = require('./lib/API');
|
|
|
-const { sessionName, sessionKeys } = require('./config');
|
|
|
+const mail = require('./notification.js')
|
|
|
|
|
|
let info = {
|
|
|
- followers: 00001,
|
|
|
+ followers: 1,
|
|
|
companyID: null,
|
|
|
orgaName: "spirit_3",
|
|
|
tokens: null,
|
|
|
+ expire: 0,
|
|
|
active: false,
|
|
|
updateTime: 2 * 60000 // 2min
|
|
|
}
|
|
|
|
|
|
+if (process.env.access_token) {
|
|
|
+ info.tokens = process.env.access_token
|
|
|
+ info.active = true
|
|
|
+}
|
|
|
+if (process.env.expire) info.expire = process.env.expire
|
|
|
+//if (process.env.usermail) mail.notif(process.env.usermail, process.env.pswd, process.env.contact);
|
|
|
+
|
|
|
+console.log("[process env TOKEN] =>", process.env.access_token);
|
|
|
+console.log("[process env expire] =>", process.env.expire);
|
|
|
+
|
|
|
+function watchLinkedin(){
|
|
|
+ console.log("watchLinkedin function");
|
|
|
+}
|
|
|
+
|
|
|
+setInterval(watchLinkedin, info.updateTime)
|
|
|
+
|
|
|
+// --- --- --- --- --- --- EXPRESS SERVER
|
|
|
+
|
|
|
app.disable('x-powered-by');
|
|
|
app.use(bodyParser.urlencoded({ extended: true}));
|
|
|
|