LinkedIn JavaScript SDK "You must specify a valid JavaScript API Domain as part of this key's configuration." - linkedin

I want to show our LinkedIn company recent updates inside our web site. so i follow these steps, to integrate with LinkedIn JavaScript SDK # https://developer.linkedin.com/docs/getting-started-js-sdk . mainly i did the following steps:-
1- I created a new application .
2- then i add the following domains inside the "Valid SDK Domains". since the site i want to show the linkedin data inside it is a sharepoint online site which has the following url https://ourcompanyname.sharepoint.com :-
3- then inside my sharepoint page , i added the following script, to get the information from LinkedIn:-
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 0**********c
</script>
<script>
alert("1");
var liLogin = function() { // Setup an event listener to make an API call once auth is complete
IN.UI.Authorize().params({"scope":["r_basicprofile", "r_emailaddress"]}).place();
IN.Event.on(IN, 'auth', getProfileData);
}
var getProfileData = function() { // Use the API call wrapper to request the member's basic profile data
alert("2");
IN.API.Profile("me").fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)").result(function (me) {
var profile = me.values[0];
var id = profile.id;
var firstName = profile.firstName;
var lastName = profile.lastName;
var emailAddress = profile.emailAddress;
var pictureUrl = profile.pictureUrls.values[0];
var profileUrl = profile.publicProfileUrl;
var country = profile.location.name;
alert(id);
});
}
</script>
<p>testing</p>
but on the browser i got the following error:-
Error: You must specify a valid JavaScript API Domain as part of this key's configuration. userspace:22:9
<anonymous>
https://www.linkedin.com/uas/js/userspace:22:9
<anonymous>
https://www.linkedin.com/uas/js/userspace:1:2
EDIT
Now based on #Lars Hendriks advice, i waited for 2 hours and i can see that the You must specify a valid JavaScript API Domain as part of this key's configuration. error is no longer showing inside my browser F12 console. but at the same time i can not see any data returned from the JavaScript call, even the alert("2") & alert(id) inside my above JavaScript did not get popup.. not sure what is going on ?

what you could try is :
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 0**********c
authorize: true
</script>
if this does not work , you might want to have to wait :
After registering an API key and specifying a valid domain, it may
take up to 30 minutes for the changes to take affect, so if it doesn't
work immediately, go grab a coffee and check back in a few.

Related

Firebase Authentication

Not sure why this code isn't running. Copied all required snippets from Firebase and my button is firing. Any ideas as to what could be going wrong? Github is making me write more stuff in here so here.
Thanks!
<head>
<meta charset=utf-8 />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auth</title>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
</head>
<body>
<button onclick="googleAuth()">SIGN UP</button>
<script>
var provider = new firebase.auth.GoogleAuthProvider();
var googleAuth = function() {
console.log(firebase);
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
};
</script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBeJIaAAD5-vK0kBDTRH6Y6_1ByVE3erJY",
authDomain: "fir-chat-d28be.firebaseapp.com",
databaseURL: "https://fir-chat-d28be.firebaseio.com",
storageBucket: "fir-chat-d28be.appspot.com",
};
firebase.initializeApp(config);
</script>
</body>
You must follow the instructions in log:
The current domain is not authorized for OAuth operations. This will prevent signInWithPopup, signInWithRedirect, linkWithPopup and linkWithRedirect from working. Add your domain to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab.
See how it says signInWithPopup will not work without your domain added in Firebase console
Follow the instructions I listed when I was having a similar error, this will enable you to solve the oAuth issue.
Firebase GAS webapp Google popup disappears
Your code looks good, but if you run that as an HTML file, you'll get an error similar to "This operation is not supported in the environment this application is running on. "location.protocol" must be http or https".
I'd suggest you to take advantage of Firebase Hosting feature. You can easily deploy and host your app's static assets like HTML, CSS, JavaScript, etc.. Moreover, it's free of charge.
in my experience ( just for advice ), dont use firebase auth with provider like google or facebook. use email and password auth for better security. you can use FirebaseUi, verry easy to understand, and you can copy-paste if you like. if you use Google auth, every user who have google account can access your apps, read, write, delete, and update. except, you have better experience with Firebase Rules.

How to get logged in user details from javascript - Alfresco

I have created a custom share page with authentication as user. Now i want to enable few buttons in the page if the logged in user is a Manager. But i don't know how to find out the logged in user is a manager or Collaborator. Can someone please help me?
In all WebScript JavaScript controllers running on the Share tier you can access user.isAdmin. This will be a boolean value indicating whether or not the current user has Administrator privileges.
However, I'm not sure if this is what you mean because you have said "Manager" - if you mean that you want to know whether or not the current user is a Manager of the current site then it will be necessary to make a request back to the Repository using the site id from the page context, there are lots of examples of this in the Alfresco codebase - essentially it should look something like this:
var userIsSiteManager = false;
var json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + encodeURIComponent(user.name));
if (json.status == 200)
{
obj = JSON.parse(json);
}
if (obj)
{
userIsSiteManager = (obj.role == "SiteManager");
}
In browser javaScript you should use ajax request
Alfresco.util.Ajax.jsonPost({
url: Alfresco.constants.PROXY_URI + webScriptUrl,
dataObj: data,
successCallback: {
fn: succesCallback,
scope: this
},
failureCallback: {
fn: faliureCallback,
scope: this
}
});
pass your request params in dataObj javaScript object.
In repository webScript use json.get("paramName")
Then use
var site = siteService.getSite(siteId);
//person - current logged in user
site.getMembersRole(person.properties.userName)

signalR script reference?

All the signalR examples shows
<script src="/signalr/hubs" type="text/javascript"></script>
without explainning enough what is it used for .
For the Html page it is a location of folder . and there is no script there.
Why and how this line is being used ?
The /signalr/hubs page is a JavaScript file that is auto generated by SignalR which contains generated hub proxies for every hub in your SignalR project.
For instance (got this from http://shootr.signalr.net/signalr/hubs) lets take a look at the code snippet.
proxies.h = this.createHubProxy('h');
proxies.h.client = { };
proxies.h.server = {
changeViewport: function (viewportWidth, viewportHeight) {
return proxies.h.invoke.apply(proxies.h, $.merge(["changeViewport"], $.makeArray(arguments)));
},
fire: function () {
return proxies.h.invoke.apply(proxies.h, $.merge(["fire"], $.makeArray(arguments)));
},
...
"this" refers to the hub connection, or rather $.connection.hub. So we're essentially saying proxies.h = $.connection.hub.createHubProxy('h');
Now 'h' is a hub on the server See https://github.com/NTaylorMullen/ShootR/blob/master/ShootR/ShootR/Server/GameHub.cs, more specifically look at the hub name attribute.
Next we have proxies.h.client; this is the endpoint for where users are able to declare their client side functions that will be invoked from the server.
We then have proxies.h.server, this references all the public hub methods on the GameHub.cs. So some of the functions are changeViewport, and fire. This code is auto generated on the server to represent each of your hubs.
Lastly at the end of the signalr/hubs file we extend all of the dynamically created hubs onto the $.connection object so users can then access them via
var myGameHub = $.connection.h;
Hope this helps!

LinkedIN Integration JS API

We are integrating with Linked IN to extract the users profile. Its working fine, but we notice in some Windows 7 / IE 9 machines, Linked IN pop up comes up and is blank. We see the below error in console.
Message: Object doesn't support property or method 'replace'
Line: 861
Char: 17
Code: 0
URI: http://platform.linkedin.com/js/framework?v=0.0.2000-RC1.21420-1403&lang=en_US
Code Snippet Below
<script type="text/javascript" src="https://platform.linkedin.com/in.js?async=false" >
api_key: tw6oqfav7ms1
authorize:false
</script>
//We have a custom image for linkedIN, onclick of the same below code is called.
$("#mylinkedin").click(function () {
IN.UI.Authorize().params({"scope":["r_fullprofile", "r_emailaddress","r_contactinfo"]}).place();
IN.Event.on(IN, "auth", onLinkedInAuth);
});
function onLinkedInAuth() {
IN.API.Profile("me").fields([ "id","firstName", "location","lastName","skills","positions","educations","languages","phone-numbers","certifications","emailAddress","mainAddress"]).result(displayProfiles);
IN.User.logout(); //After we take the data, we do a log out
$.get("https://api.linkedin.com/uas/oauth/invalidateToken");
}
function displayProfiles(profiles) {
//Access profile and process
member = profiles.values[0]
...........
}
Thanks for your response.I was able to figure the issue on my own. What we observed was in the Win7 machines with IE9, the Linked IN authorization Pop Up was blank. When I uncheck the "Enable Protected Mode" the pop up is coming up without any issues.
I haven't had a chance to test this, but to me it looks like you've introduced a race condition in your code, specifically, in onLinkedInAuth().
The call to IN.API.Profile() invokes an async call to LinkedIn that may not be complete by the time the JavaScript engine in the IN.User.logout() code.
I would change the code to the following to see if this resolves the issue:
IN.API.Profile("me")
.fields([ "id","firstName", "location","lastName","skills","positions","educations","languages","phone-numbers","certifications","emailAddress","mainAddress"])
.result(function(profile) {
displayProfiles(profile);
IN.User.logout(); //After we take the data, we do a log out
$.get("https://api.linkedin.com/uas/oauth/invalidateToken");
});

Need good example: Google Calendar API in Javascript

What I'm trying to do:
Add events to a google calendar from my site using javascript.
What I can't do:
Find a good tutorial/walk through/example for the google calendar api. All the documentation I've been able to find links back and forth between v1 and v2 api's, or the v3 api doesn't seem to be client based.
For those that are curious, the site I'm developing this for:
http://infohost.nmt.edu/~bbean/banweb/index.php
Google provides a great JS client library that works with all of Google's discovery-based APIs (such as Calendar API v3). I've written a blog post that covers the basics of setting up the JS client and authorizing a user.
Once you have the basic client enabled in your application, you'll need to get familiar with the specifics of Calendar v3 to write your application. I suggest two things:
The APIs Explorer will show you which calls are available in the API.
The Chrome developer tools' Javascript console will automatically suggest method names when you are manipulating gapi.client. For example, begin typing gapi.client.calendar.events. and you should see a set of possible completions (you'll need the insert method).
Here's an example of what inserting an event into JS would look like:
var resource = {
"summary": "Appointment",
"location": "Somewhere",
"start": {
"dateTime": "2011-12-16T10:00:00.000-07:00"
},
"end": {
"dateTime": "2011-12-16T10:25:00.000-07:00"
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': resource
});
request.execute(function(resp) {
console.log(resp);
});
Hopefully this is enough to get you started.
this should do the trick
//async function to handle data fetching
async function getData () {
//try catch block to handle promises and errors
try {
const calendarId = ''
const myKey = ''
//using await and fetch together as two standard ES6 client side features to extract the data
let apiCall = await fetch('https://www.googleapis.com/calendar/v3/calendars/' + calendarId+ '/events?key=' + myKey)
//response.json() is a method on the Response object that lets you extract a JSON object from the response
//response.json() returns a promise resolved to a JSON object
let apiResponse = await apiCall.json()
console.log(apiResponse)
} catch (error) {
console.log(error)
}
}
getData()

Resources