Linkedin Javascript SDK - javascript

I am trying to call an API to get user information but its always giving me this error: Could not find person based on: ~, below is my code to call the people API:
IN.API.Raw('/people/~:(id,first-name,last-name,maiden-name,headline,location,industry,picture-url,summary,specialties,positions,picture-urls::(original),email-address,num-connections,site-standard-profile-request,api-standard-profile-request,public-profile-url)?format=json').result((data) => {
callback(data);
}).error((error) => {
console.log('Error:', error);
});

Related

Copied example from documentation of Youtube API not working

I'm trying to search for a video with some words using Youtube API and I have run my example on this interactive app https://developers.google.com/youtube/v3/docs/search/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22q%22%3A%22ay%20vamos%22%7D. I have copied the source code on that page and removed authorization because I don't need it and filled credentials. This is the error I keep on getting Uncaught TypeError: Cannot read property 'youtube' of undefined
<body>
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.search.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function loadClient() {
gapi.client.setApiKey("-------------------");
return gapi.client
.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(
function () {
return gapi.client.youtube.search
.list({
part: ["snippet"],
q: "ay vamos",
})
.then(
function (response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function (err) {
console.error("Execute error", err);
}
);
},
function (err) {
console.error("Error loading GAPI client for API", err);
}
);
}
// Make sure the client is loaded and sign-in is complete before calling this method.
</script>
<button onclick="loadClient()">execute</button>
</body>
"Cannot read propery 'youtube' of undefined" hints that gapi.client isn't defined properly. I ran your code myself and printing gapi.client to the console outputs null.
Also, I couldn't find anything that is calling your loadClient() function which looks like it is responsible for actually loading the youtube client? That could be a separate issue.

NodeJs - Call API Url Link with another API

Problem: I'm trying to connect an API url link through another API function.
API Url (Provided by Third Party): http://garden.home.com:8080/api/GetAllHome
API Link (Created by me): http://localhost:3000/town/house
The API link created by me is just meant to be a API function which will contain the provided API url. I'm trying to connect to the API provided thought my function but I'm encountering problems.
I've tried using http.get and axios.get but I've encountered several problems
Using http.get
Error: getaddrinfo ENOTFOUND garden.home.com garden.home.com:8080
"message": "http.get(...).then is not a function"
app.get('/town/house', (req, res, next) => {
http.get(allHouseUrl)
.then(response => {
console.log(response.data.url);
console.log(response.data.explanation);
})
.catch(error => {
console.log(error);
});
});
const allHouseUrl = {
host: 'garden.home.com',
port: 8080,
path: '/api/GetAllHome'
}
I tried the online solutions, which was to wrote their url details in an object and call it.
Using axios.get
Error: getaddrinfo ENOTFOUND garden.home.com garden.home.com:8080
app.get('/town/house', (req, res, next) => {
axios.get("http://garden.home.com:8080/api/GetAllHome")
.then(response => {
console.log(response.data.url);
console.log(response.data.explanation);
})
.catch(error => {
console.log(error);
});
});
My desired results would be to connect to the provided url link and be able to pass parameters to it.
I am able to to retrieve the json data from http://garden.home.com:8080/api/GetAllHome by using Postman but I am unable to access it through an API function that I created.

Error with the promise/catch from a Firestore query

I've modified the code below a bit but this is an externally facing endpoint where a mobile client can ping this endpoint and send some pushes to appropriate users.
However, in my console, I'm getting an error:
UnhandledPromiseRejectionWarning: TypeError: assert.isNotOk is not a function
function myFunc(request, response) {
var db = firestore.firestore();
db.collection("myCollection")
.doc(request.params.someParam)
.get()
.then(docSnapshot => {
if (docSnapshot.exists) {
for (var userId of request.params.userIds) {
sendPush(userId, request.params);
continue;
} else {
response.error("Unable to get param");
}
}).catch((error) => {
assert.isNotOk(error, 'Promise error');
done();
});;
});
Any idea what I'm doing wrong here? Thanks
As you can see in the documentation for node's assert, there is no method called isNotOk. However, this is a method called ok. In any event, it's not clear to me what you're trying to do with that line, since you already know at that point that there's an error. Perhaps you just want to log it?

How to show a ERR_NAME_NOT_RESOLVED error to user

My app allows users to specify a server name which is where their installation of our api is. This is so the rest of the app can make calls to that endpoint.
However, I need to display an error message to if we get an error like ERR_NAME_NOT_RESOLVED and it seems that I'm not able to catch this as an error in javascript.
Is there any way around this?
What're you using to make the call to the endpoint? if you're using fetch you don't have an exception, the response is an object with a property error in true and the error messages.
response = {
error: true,
data: { message: 'ERR_NAME_NOT_RESOLVED', code: 404 }
}
If you're using axios, you have to make something like this:
axios.post('/formulas/create', {
name: "",
parts: ""
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
});

Uncaught ReferenceError: init is not defined

im a newbie in javascript and wanted to learn something, I've been wondering, i found this on https://developers.google.com/api-client-library/javascript/features/cors where i can use cors so i can access a google API like kissflow, i dont know if im in the right way. so here's the thing, im using the standalone Auth client that was described in the said site, but everytime i tried to run the program the error prompt
Uncaught ReferenceError: init is not defined
i just copied the code at the site which is
<script src="https://apis.google.com/js/api.js"
type="text/javascript">
</script>`<script type="text/javascript">`
//<![CDATA[gapi.load('auth', init);//]]>
</script>
Try this:
<script src="https://apis.google.com/js/api.js"
type="text/javascript">
</script>
<script>
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "<YOUR_CLIENT_ID>"});
});
</script>
Make sure that you host this locally, and when creating the client ID, add the localhost URL with the port. Without a URL, the client ID will not send back a proper response, resulting in an error. Since the client ID doesn't support "file:///", you have to use a web hosting service or something, or the easier route, just download the latest python and set up a localhost server.
Latest python download: https://www.python.org/downloads/
Setting up the server: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server#running_a_simple_local_http_server
Note that sometimes you have to use "py" instead of "python" for reasons I am too lazy to research 😊.
To actually initiate the login and use the API:
<script>
function authenticate() {
return gapi.auth2.getAuthInstance().signIn({scope: ""/*Declare scopes with spaces in between, depends on API you're using*/})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("<YOUR_API_KEY>");
return gapi.client.load(""/*Declare discovery document, depends on API you're using*/)
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
function execute() {
return gapi.client.classroom.courses.list({}) //Used classroom courses list as an example, but use the apropriate API Fields, found in your method's "Overview" section on the API Documentation
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "<YOUR_CLIENT_ID>"});
});
authenticate().then(loadClient).then(execute)
</script>
Note that sometimes you have to clear cache in order for this to work (I mean, worked for me), so if you have some trouble, try that.

Categories

Resources