|
@@ -11,7 +11,8 @@ if (process.env.usermail) mail.notif(process.env.usermail, process.env.pswd, pro
|
|
|
|
|
|
let info = {
|
|
|
numberFollower: 0000,
|
|
|
- companyID: 10121467,
|
|
|
+ companyID: null,
|
|
|
+ orgaName: "spirit_3",
|
|
|
appID: "86wenleyh4u42g",
|
|
|
secret: "CCv35kAHKCuXFqEX",
|
|
|
scope :[
|
|
@@ -41,46 +42,47 @@ 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: {
|
|
|
+ 'X-Restli-Protocol-Version': '2.0.0',
|
|
|
+ 'Authorization': `Bearer ${info.tokens.access_token}`
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .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();
|
|
|
|
|
|
- // console.log(linkedin);
|
|
|
- // console.log("AFTER INIT", info.companyID)
|
|
|
- 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`
|
|
|
-
|
|
|
- axios.post(testorgaRoute,
|
|
|
- bodyParameters,
|
|
|
- {
|
|
|
- headers: {
|
|
|
- 'X-Restli-Protocol-Version': '2.0.0',
|
|
|
- 'Authorization': `Bearer ${info.tokens.access_token}`
|
|
|
- },
|
|
|
- })
|
|
|
- .then(function (response) {
|
|
|
- console.log(response);
|
|
|
- })
|
|
|
- .catch(function (error) {
|
|
|
- console.log(error);
|
|
|
- console.log("error")
|
|
|
- });
|
|
|
-
|
|
|
- // linkedin.connections.retrieve(function(err, connections) {
|
|
|
- // // Here you go! Got your connections!
|
|
|
- // if (err) console.log("error get connections", err);
|
|
|
-
|
|
|
- // console.log(json.PARSE(connections));
|
|
|
- // console.log(connections);
|
|
|
- // });
|
|
|
- console.log("test companies")
|
|
|
- } catch (error) {
|
|
|
- console.log(error);
|
|
|
- console.log("[Authorization Error] on getting company information")
|
|
|
+ if (!info.companyID){
|
|
|
+ // find the organisation ID
|
|
|
+ console.log("Try Request to get Company ID")
|
|
|
+ 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")
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|