linked in data scraper in node.js - node.js

In my code linkedInProfile is not a function that error display in console how to solve that error???
var linkedInProfile = require('linkedin-public-profile');
app.get('/api/webapi/:version/users', function(req,res){
var url = 'https://www.linkedin.com/in/bansridamani/';
linkedInProfile(url).then(profile => {
console.log(profile);
});
var request = require('request-promise');
request(url)
.then(html => linkedInProfile(html))
.then(profile => {
console.log(profile);
});
});

Actually, you are using dead repo for scraping public data of linkedin profiles linkedin-public-profile.
And please check the api documentations of linkedin REST API to here.
Also check the linkedin API console to here for testing.
Hope this will help you!

Related

problems trying to use the Instagram api

I am working with Angular and Node.js with Express.js. I have all day trying to get the posts from my Instagram account but I have not even been able to get the API token. I understand that you first have to make a request to this URL: https://api.instagram.com/oauth/authorize?client_id=[instagram-app-id-lex.europa.eu&redirect_uri=[redirect-uriíritu&scope=[scope-lex.europa.eu&response_type=code&state = {state} (replacing the id and redirect-uri obviously) but I get no response. I already created my app in the instagram api following its documentation and add the tester and accept the authorization from the account settings.
At the moment I have this code en node.js:
const instagram = require('../controllers/instagram/instagram.controller');
const route = '/auth'
module.exports= (app,db, protegerRutas)=> {
app.get(`${route}/instagram`, (req, res)=> instagram.auth(req, res));
app.get(`/handle`, (req,res)=> instagram.handleauth(req,res));
// app.get(`${}`)
// app.post(`${route}/actualizar`, protegerRutas, (req, res)=> actualizar.actualizarDatos(req, res, db))
}
controller:
const Instagram = require('node-instagram').default;
const axios = require('axios');
const clavesInstagram = require('../../config/config').instagram;
const {clientId, clientSecret}= clavesInstagram;
const urlInstagram = 'https://api.instagram.com/oauth/authorize?client_id=201577004938695&redirect_uri=https://localhost:3008/auth/handle&scope={scope}&response_type=code';
const redirectUri = 'https://b4ae544459e3.ngrok.io/handle';
const instagram = new Instagram({
clientId: clientId,
clientSecret: clientSecret
})
module.exports= {
auth: (req,res)=> {
axios.get(urlInstagram)
.then( res => {
console.log('\n\nRespuesta: ',res);
})
.catch( err => {
console.log('\n\nError: ',err);
})
},
// auth: (req, res)=> {
// console.log('\n\nAuth Controller...')
// res.redirect(
// instagram.getAuthorizationUrl(redirectUri, {
// scope: ['basic','likes'],
// state: 'your state'
// })
// )
// },
handleauth: async (req, res)=> {
try {
console.log('\n\n\n\nHandleAuth....\n\n\n\n\n')
const code = req.query.code; //código devuelto por Instagram
const data= await instagram.authorizeUser(code, redirectUri);
console.log('\n\nData Instagram:', data)
res.json(data);
} catch(e) {
// statements
console.log(e);
res.json(e)
}
}
}
I understand that in the instagram API configuration the URL of my app is added to which they redirect and send the token, the url of my local app is something like this: http://localhost:3008/ and the path to which I want instagram to redirect would be this: https://localhost:3008/auth/handle (I must put it with 'https' in instagram because it does not allow http, so I don't know if this would include me). The problem is that with this code I am not getting the token that should be sent to my route https://localhost:3008/auth/handle. What am I doing wrong? I've been at this for many hours and honestly I can't find a solution. I read the documentation and try to do what it says but I can't do it. Could someone help me with this? I would be enormously grateful.
Thanks in advance.

Firebase on Express - Can't return response to client with .catch(error)

I've searched for hours and could not find a single relevant thing about this.
I am using firebase on my express web server for user (admin) authentification. I basically have a separate control panel for the admins separate from the mobile app so we can control the data from the users.
I currently have this post address that does the following:
app.post('/createNewAdminAccount', function(req, res){
const password = bcryptPassword(bcryptDetails, req.body.password);
const username = req.body.username;
const auth = firebase.auth();
let userExists = false;
function userExistsResponse(){
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ "userExists": true }));
}
const promise = auth.createUserWithEmailAndPassword(username, String(password));
promise.catch(function(error){
console.log(error.message);
userExistsResponse();
});
});
The way I have userExistsResponse(); isn't exactly how I have it, but for the sake of clarity, it's like that.
It seems that the .catch() function can only accept console.log(). I even looked at this which suggests stacking a .then(), error(error) but that doesn't work no matter how I write it, and using catch(error) doesn't seem to work either.
The goal is to see that the user is authenticated and respond to the client with a message as such. I've tried setting a variable to true (as you can see by the leftover let userExists = false variable), calling a function, doing a .then() statement without a .catch() (causes the server to break with an error), etc. None of it works, and after looking through YouTube videos, Firebase documentation, and StackOverflow, I have not found a useful answer.
FIXED Credit: 0x17
app.post('/createNewAdminAccount', authenticated, function(req, res){
const password = String(bcryptPassword(bcryptDetails, req.body.password));
const username = req.body.username;
admin.auth().getUserByEmail(username)
.then(function(userRecord) {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ 'userExists': true }));
console.log('User Exists');
})
.catch(function(error) {
const promise = auth.createUserWithEmailAndPassword(username, password);
promise.catch(function(error){
console.log(error.message);
});
console.log('User Created');
});
});
From the way i see it, for the createNewAdminAccount route, Why not you do a check for the user in the first place using admin.auth().getUserByEmail(); analyse it's response code auth/email-already-exists or a combination of some listed in this link and then proceed with admin.auth().createUser() ?
Also if your goal is to just authenticate the user, should you not be using the below mentioned method and analyze the error code for the same ?
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});

Cloudrail - OneDrive API : Advanced search request fails

I'm using cloudrail Node.Js v2.17.3.
I have to do an advanced request on OneDrive API.
The authentication part and getting/storing credentials have succeeded.
Here is the request I have to do (according to OneDrive's doc):
/drive/root/search(q='IMG_001.jpg')
Of course, the file is present in my OneDrive account.
Here is the code :
const req = new cloudrail.types.AdvancedRequestSpecification("/drive/root/search(q='IMG_001.jpg')");
req.setMethod("GET");
req.setHeaders({"Content-Type": "application/json"});
service.advancedRequest(req, (err, res) => {
console.log(err, res);
});
Err.message says : "Invalid API or resource".
However, when I try the simple request "/drive/root/children", it works...
Thank you in advance.
Microsoft recently introduced their new Graph API which is used by all of the services as far as I know. So the documentation you are referring to is for the new API.
Try using '/drive/items/{the_folder_id or root}/view.search?q=txt' instead. You also might need to url encode the parameter. So the safest solution would probably be sth like that:
const url = "/drive/items/root/view.search?q=" + encodeURIComponent("[search query]");
const req = new cloudrail.types.AdvancedRequestSpecification(url);
req.setMethod("GET");
service.advancedRequest(req, (err, res) => {
console.log(err, res);
});

Nodejs Google Oauth2 callback returns http 500 error

I am trying to practice Google Apis and learn express
I am following the Google Oauth2 implementation using Nodejs . Please follow the link
I am able to generate the URL which would redirect me to Google website and once the permissions are granted the callback always fails. I think the my callback route function is never invoked following are the values in the url
I would have the following in the url
http://localhost:3000/googlecallback?code=[my code]
and the get route code is as below
app.use("/googlecallback", function(req, res) {
var oauth2Client = getOAuthClient();
var session = req.session;
var code = req.query.code;
oauth2Client.getToken(code, function(err, tokens) {
// Now tokens contains an access_token and an optional refresh_token. Save them.
if (!err) {
oauth2Client.setCredentials(tokens);
session["tokens"] = tokens;
res.send('User Authenticated');
} else {
res.send('User Authentication failed');
}
});
});
Any help would be greatly appreciated.
Any help would be greatly appreciated.

Node.js OAuth2: Get Google+ activities

From today I'm not able to retrieve my Google+ activities by placing a GET request to this url:
https://www.googleapis.com/plus/v1/people/me/activities/public?key={API_KEY}
I'm getting a 401 error. So I tried to sign the request using the node.js oauth2 library, including a pre-generated user token, but I'm getting the same error. The js code for my test script is:
var OAuth2 = require('oauth').OAuth2,
GOOGLEPLUS_APP_ID = {APP_ID},
GOOGLEPLUS_APP_SECRET = {APP_SECRET},
accessToken = {USER_TOKEN};
var _oauth2 = new OAuth2(GOOGLEPLUS_APP_ID, GOOGLEPLUS_APP_SECRET, '',
'https://accounts.google.com/o/oauth2/auth',
'https://accounts.google.com/o/oauth2/token');
_oauth2.get('https://www.googleapis.com/plus/v1/people/me/activities/public?key={API_KEY}',
accessToken, function (err, body, res) {
if (err) {
console.log('error:');
console.log(err);
}
else console.log(body);
});
I placed the same request to get the basic user info (url: https://www.googleapis.com/oauth2/v1/userinfo) and works OK.
Can you please assist me with this?
Thank you.
If you have the access token already you should be able to use {?|&}access_token=X to get the result, example below.
var accessToken = 'XYZ';
require('http').get('https://www.googleapis.com/plus/v1/people/me/activities/public?access_token=' + accessToken, function(result){
//Use result here!
});
More information can be found within the Google+ API (Common Parameters) section

Resources