Unable to get entire information from linkedIn api - javascript

I have tried this
Html:
<a id="li_ui_li_gen_1432549871566_0-link" class="" href="javascript:void(0);" onclick="onLinkedInLoad();" style="margin-bottom: 20px;">
JS code:
function onLinkedInLoad(logintype) {
IN.User.authorize(function(){
callback();
});
}
function callback(){
IN.Event.on(IN, "auth", OnLinkedInAuth);
OnLinkedInAuth();
}
function OnLinkedInAuth(){
IN.API.Profile("me")
.fields("firstName", "lastName", "industry", "location:(name)", "picture-url", "headline", "summary", "num-connections", "public-profile-url", "distance", "positions", "email-address", "educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes)","languages:(id,language:(name),proficiency:(level,name))","skills:(id,skill:(name))", "date-of-birth")
.result(ShowProfileData)
.error(displayProfilesErrors);
}
function ShowProfileData(profiles) {
console.log(profiles); return false;
//its gives me json responce
/* {
"_total": 1,
"values": [{
"_key": "~",
"distance": 0,
"emailAddress": "xxxxx#gmail.com",
"firstName": "xxxx",
"headline": "xxxxx",
"industry": "Information Technology and Services",
"lastName": "xxx",
"location": {"name": "xxx Area, India"},
"numConnections": 117,
"positions": {
"_total": 1,
"values": [{
"company": {
"id": xxxxx,
"industry": "E-Learning",
"name": "xxxx",
"size": "501-1000 employees",
"type": "Privately Held"
},
"id": 485779823,
"isCurrent": true,
"startDate": {
"month": 2,
"year": 2013
},
"title": "xxxxx"
}]
},
"publicProfileUrl": "https://www.linkedin.com/pub/xxxxx/xx/xx/xx"
}]
} */
}
function displayProfilesErrors(error) {
profilesDiv = document.getElementById("profiles");
profilesDiv.innerHTML = error.message;
console.log(error);
}

It looks to me that some queried fields (e.g. languages, skills, education fields) require that your application have been approved for the Apply with LinkedIn program.
See: Profile field descriptions page which lists fields that require an additional API (i.e. 'Member profile fields available to Apply with LinkedIn developers' title), and see how one can apply for using this API: Request access to this API page.

Related

Querying a nested array in MongoDB

This is my posting document in MongoDB:
{
"_id": {
"$oid": "5b4e60ab24210138f5746402"
},
"type": [
"full",
"temp"
],
"applications": [
{
"_id": {
"$oid": "5b52113d1123631744fa9f39"
},
"applicationDate": {
"date": 20,
"day": 5,
"hours": 18,
"minutes": 43,
"month": 6,
"seconds": 41,
"time": 1532105021753,
"timezoneOffset": -120,
"year": 2018
},
"userId": {
"$oid": "5b51fb6f9686430cee31a0d9"
},
"resume": {
"fieldname": "resume",
"originalname": "resume_acc.pdf",
"encoding": "7bit",
"mimetype": "application/pdf",
"destination": "./public/resumes/",
"filename": "765d650b9014cc3ddadb801d10d495a5",
"path": "public/resumes/765d650b9014cc3ddadb801d10d495a5",
"size": 8
},
"coverLetter": {
"fieldname": "docs",
"originalname": "cover letter.pdf",
"encoding": "7bit",
"mimetype": "application/pdf",
"destination": "./public/resumes/",
"filename": "e5892869b24f3fc5e72d3e057b4dd61d",
"path": "public/resumes/e5892869b24f3fc5e72d3e057b4dd61d",
"size": 5
}
}
],
"creatorId": {
"$oid": "5b4b95cc16778c325010a55d"
},
"title": "Developer",
"salary": "50/h",
"timeLine": "One year",
"description": "You'll be building apps",
"duties": "Building apps",
"experience": "2 years",
"province": "ON",
"visible": true,
"__v": 0
}
Postings is an array of posting, which look like the above document. applications is an array which is in every posting. I want to search all postings.applications to see get all postings the user applied to. For now I tried to do it like this:
var Posting = require('../models/posting');
var postings = await Posting
.find({'visible': true});
console.log('posts', postings);
var applications = await Posting
.find({'visible': true})
.where(postings
.map(posting => posting.applications
.map(application => application.userId.equals(req.user._id)))
);
But obviously this failed.
I tried this as well:
var postings = await Posting
.find({'visible': true, 'applications[$].userId': req.user._id});
or
var postings = await Posting
.find({'visible': true, 'applications.$.userId': req.user._id});
But no luck. They both return an empty array.
Posting model:
var mongoose = require('mongoose');
jobPostingSchema = mongoose.Schema({
"creatorId": mongoose.Schema.Types.ObjectId, //ObjectID('aaaa'), // ID of the User or Account
"eventId": {'type': mongoose.Schema.Types.ObjectId, 'default': undefined},
"title": String,
"type": [], //"Full", // What this means? I did not understand.
"salary": String,
"timeLine": String, // What this means? I did not understand.
"description": String,
"duties": String,
"experience": String,
"province": String, // Employer will post job postings based on the province and region
// Applications means, how many people applied for this job post?
"applications": [
// {
// ObjectID: cccc,
// userId: dddd,
// Resume: {},
// coverLetter: String,
// },
],
"visible": Boolean,
});
module.exports = mongoose.model('posting', jobPostingSchema);
So how can I get all applications where userId equals req.user._id?
Maybe this works as a solution ( sourcing from the SO link shared by #DSCH here ):
Posting.find({
'applications': {
$elemMatch: { userId: req.user._id }
},
'visible:': true
});
If you wish to seek clarification on how it works, you may refer to the link here
Posting.find({
'visibile:': true,
'applications': {
$elemMatch: { userId: req.user._id }
}
});
$elemMatch is the mongo operator that you probably need.
Hope that one helps better.

How do I expand nested relationships in REST API using Sails.js

I am a newbie to NodeJS and Sails.js.
I want create a REST API that allows me to expand a resource based on query parameter. For eg
HTTP GET /snippets
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "htep://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": "http://localhost:8000/users/2/",
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
HTTP GET /snippets?expand=owner
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "http://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": {
"url": "http://localhost:8000/users/2/",
"username": "test",
"email": "test#test.com"
},
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
Wondering how can I do that in Sails.js or NodeJS?
You should use assocations.
Here is how you would create a one-to-many association between your User model and your Snippet model:
// User.js
module.exports = {
// ...
attributes: {
// ...
snippets: {
collection: 'Snippet',
via: 'owner'
}
}
};
// Snippet.js
module.exports = {
// ...
attributes: {
// ...
owner: {
model: 'User'
}
}
};
Then you can hit /snippets if you want a list of snippets, and hit /snippets?populate=[owner] if you need details about the owners of the snippets.

PouchDb - remove object inside document

I'm an Italian PouchDb and AngularJS Developer.
My json document is:
{
"_id": "6",
"_rev": "3-f7283d7683cd6fb15753f494aad1d49f",
"name": "Ivrea",
"owners": [
{
"owner_id": 1,
"name": "asdas",
"address": "asdas",
"gender": "Uomo",
"type": "Assente",
"notes": [
]
},
{
"owner_id": 2,
"name": "balbaba",
"address": "blabla",
"gender": "Uomo",
"type": "Assente",
"notes": [
]
}
]
}
and after an ng-click action, I will delete owner_id: 2 object inside _id: 6 document. In API reference I found only document delete action, but not how to delete object inside document.
Thanks for your reply!!
Alessandro
You just need to put() the main document back in the database after you remove an object from it. :)
db.get('foo').then(function (doc) {
delete doc.whatever;
return db.put(doc);
}).catch(function (err) { /* ... */ });

Show latest facebook post on website

I'm having trouble in showing the latest post of my Facebook page in my website without using PHP since the website is not hosted in an Apache server.
What I've done till now:
Created a Facebook app and generated an Access token.
Access to Facebook Developer Graph explorer, and used GET method
https://developers.facebook.com/tools/explorer?method=GET&path=nextgenerationmorocco%2Ffeed%3Flimit%3D1&version=v2.0
The result after clicking on Graph Explorer submit button:
{
"data": [
{
"id": "421944571240838_501444706624157",
"from": {
"category": "Organization",
"category_list": [
{
"id": "162237190493977",
"name": "Computer Training"
},
{
"id": "108472109230615",
"name": "Computer Services"
}
],
"name": "Next Generation I.T.",
"id": "421944571240838"
},
"message": "Inscriptions ouvertes pour la formation symfony2\nProfil du formateur : Ingénieur d'état, 5 ans d'expérience.",
"picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCyB9kEztxV2fnb&w=154&h=154&url=http%3A%2F%2Fngitmaroc.com%2Fimg%2Fportfolio%2Fformation-web-1.jpg",
"link": "http://ngitmaroc.com/formation-web.html",
"name": "Formation Web",
"caption": "ngitmaroc.com",
"description": "Formation programmation/développement site application web php5 symfony2 Maroc Oujda",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"created_time": "2014-06-01T12:17:22+0000",
"updated_time": "2014-06-01T12:17:22+0000",
"likes": {
"data": [
{
"id": "1459899217586855",
"name": "Nassira Said"
},
{
"id": "1484688285098548",
"name": "Mohamed Tizaoui"
},
{
"id": "1458333711077710",
"name": "Hasnae Lazaar"
},
{
"id": "574623632656391",
"name": "KaOûtar OuJdiia"
}
],
"paging": {
"cursors": {
"after": "NTc0NjIzNjMyNjU2Mzkx",
"before": "MTQ1OTg5OTIxNzU4Njg1NQ=="
}
}
}
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.0/421944571240838/feed?limit=1&since=1401625042",
"next": "https://graph.facebook.com/v2.0/421944571240838/feed?limit=1&until=1401625041"
}
}
How can I use Javascript to fetch these information and show them on my website : "message", "from", "created_time"? Any help will be highly appreciated since I'm new to Javascript and Facebook developers!
You alternatively may use Facebook Likebox plugin to show your recent posts in your website.

Request a complete response object instead of compact reponse object foursquare venues search api?

When we request a api call to foursquare for search venues of certain category
It returns a compact response not complete response because of which i am not able to get complete information about the place like if the place is open, price etc which is only returned in a complete response, can i get a complete response instead of compact response?? more info provided here.
Eg:
call:https://api.foursquare.com/v2/venues/search?ll=18.5308225,73.8474647&categoryId=4bf58dd8d48988d1e1931735&radius=1000&v=20131021&limit=1
Result:
{
"meta": {
"code": 200
},
"response": {
"venues": [{
"id": "4b975471f964a520c9ff34e3",
"name": "Yana Sizzler & Wok",
"contact": {
"phone": "+912066013897",
"formattedPhone": "+91 20 6601 3897"
},
"location": {
"address": "F C Road",
"lat": 18.52802688063791,
"lng": 73.84272476029567,
"distance": 589,
"cc": "IN",
"city": "Pune",
"state": "India",
"country": "India"
},
"categories": [{
"id": "4bf58dd8d48988d1df931735",
"name": "BBQ Joint",
"pluralName": "BBQ Joints",
"shortName": "BBQ",
"icon": {
"prefix": "https:\/\/ss1.4sqi.net\/img\/categories_v2\/food\/bbq_",
"suffix": ".png"
},
"primary": true
}],
"verified": false,
"restricted": true,
"stats": {
"checkinsCount": 542,
"usersCount": 402,
"tipCount": 19
},
"specials": {
"count": 0,
"items": []
},
"hereNow": {
"count": 0,
"groups": []
},
"referralId": "v-1386276988"
}]
}
}
But i am not getting informatiion like isOpen Price etc which we get in the complete response when we use explore.
The API does not support returning complete objects in venue search responses—you need to make a separate venue details call to get the information you're looking for. We recommend caching venue details (for up to 30 days) to avoid having to repeatedly calling this endpoint to retrieve this information that doesn't necessarily change that often.

Categories