How to get user email id using hello.js? - javascript

I am trying to login website with hello.js. I get the user name but I can't get user email id. How can I get this?
I am following this link.
This is my code :
<script src="hello.js" ></script>
<script>
hello.init({
google: "742850147964-r4pfusmgmp2mtfbngh387e30k3692p79.apps.googleusercontent.com"
}, {redirect_uri: 'index.php'});
hello.on('auth.login', function(auth) {
// Call user information, for the given network
hello(auth.network).api('/me').then(function(r) {
console.log("r.email = "+r.email);
console.log("r.name== = "+r.name);
});
});
</script>

I got my problem solved by simple changing in the hello.js.
for google :-
scope: {
basic: 'https://www.googleapis.com/auth/plus.me profile',
}
to
scope: {
basic: 'https://www.googleapis.com/auth/userinfo.email',
}
for facebook :-
scope: {
basic: 'public_profile',
}
to
scope: {
basic: 'public_profile,email',
}

First, please keep just one js file ref, you don't need both:
<script src="hello.js" ></script>
<script src="hello.min.js" ></script>
I tried adding the button for google and it worked, I think something is wrong with the configuration for Yahoo, check if the client id is correct.

Related

Issue with Auth0 and javascript Lock v11

I'm trying to test a basic authentication module on my web app using auth0 and Lock v1 login form.
This is a snapshot of the code I'm using:
<script src="https://cdn.auth0.com/js/lock/11.23.1/lock.min.js"></script>
<script type="text/javascript" src="js/auth0variables.js"></script>
<script type="text/javascript" src="js/auth0app.js"></script>
<script>
$( document ).ready(function() {
console.log("start");
var lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN, {
auth: {
redirectUrl: 'undefined',
responseType: 'code',
params: {
scope: 'openid email' // Learn about scopes: https://auth0.com/docs/scopes
}
}
});
lock.show();
});
</script>
The problem is that I'm not able to get the auth0 modal since I'm getting the following error:
Uncaught TypeError: Cannot read property 'protocol' of null
at Object.getOriginFromUrl (auth0.min.esm.js:8)
at G.run (auth0.min.esm.js:8)
at $.checkSession (auth0.min.esm.js:8)
at nt.getSSOData (auth0.min.esm.js:8)
at t.getSSOData (p2_api.js:190)
at t.getSSOData (web_api.js:64)
at t.fetchFn (data.js:4)
at t.fetch (cache.js:17)
at t.get (cache.js:13)
at r (data.js:7)
I don't understand if I'm configuring in a wrong way my application on Auth0 dashboard, if I'm missing some configuration parameter calling the the Auth0Lock method or if the issue is somewhere else.
Can anybody help me with this? Thanks!
I found a workaround looking at the following discussion hosted on ath0 github repo:
https://github.com/auth0/lock/issues/1638
In order to avoid getLocationFromUrl returning null value I set the redirectUrl option in Auth0Lock constructor
<script src="https://cdn.auth0.com/js/lock/11.23.1/lock.min.js"></script>
<script type="text/javascript" src="js/auth0variables.js"></script>
<script type="text/javascript" src="js/auth0app.js"></script>
<script>
$( document ).ready(function() {
console.log("start");
var lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN, {
auth: {
redirectUrl: 'http://localhost',
//redirectUrl: 'file://',
responseType: 'code',
params: {
scope: 'openid email' // Learn about scopes: https://auth0.com/docs/scopes
}
}
});
lock.show();
});
</script>
Both redirectUrl: 'http://localhost' or redirectUrl: 'file://' options are working fine for my development purposes.

FB.ui feed or share not returning post_id response

I am trying to use FB.ui share or feed on my test web site and want to get post_id on response message. App has permissions from my test user (user_posts, public_profile) and also i am checking if login status is "connected".
this is javascript code that i am trying to check login and let user to share link. shareOnFacebook() is triggered by a simple html button;
<script async defer src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: '****************',
cookie: true,
xfbml: true,
version: 'v5.0'
});
};
function shareOnFacebook() {
FB.getLoginStatus(function (response1) {
console.log(response1)
if (response1.status === 'connected') {
FB.ui({
method: 'feed',
link: 'http://www.linktoshare.com',
picture: 'http://www.linktoshare.com/images/imagethumbnail.png'
}, function (responseEnd) {
if (responseEnd) {
console.log(responseEnd);
alert('Success');
} else {
alert('Fail');
}
});
}
else {
FB.login(function (response2) {
console.log(response2)
FB.ui({
method: 'feed',
link: 'http://www.linktoshare.com',
picture: 'http://www.linktoshare.com/images/imagethumbnail.png'
}, function (responseEnd) {
if (responseEnd) {
console.log(responseEnd);
alert('Success');
} else {
alert('Fail');
}
})
});
}
});
}
</script>
As you can see from below image, if i close pop-up, i can get response image like that;
But when i share, reponse returns as an empty array like that;
I know the error about "Https" is not important because my app is on development status.
What should i do to get post_id on response here?
Thank you very much.
What should i do to get post_id on response here?
You can’t get the post ID any more, Facebook has removed that completely.
It was getting abused by shady developers and website owners to try and force users to share stuff, to get some kind of reward - which is absolutely not allowed. To stop that kind of spam, Facebook has removed this a while ago already.

Getting This page isn't available error while sharing localhost page in Facebook

I am trying to share my localhost page into facebook. But I am getting This page isn't available message.
I registered my app. Below are the details
App ID - 2129405327086578,
App Domains - loachost ,
Site URL - http://localhost:56897
Below is my code
<button id="shareonfacebook">ShareOnFaceBook</button>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js"></script>
<script src="https://connect.facebook.net/en_US/all.js"</script>
<script type="text/javascript">
$(document).ready(function () {
$('#shareonfacebook').click(function (e) {e.preventDefault();
FB.ui(
{
method: 'popup',
name: 'TestShare',
href: 'http://localhost:56897/MyPage?id=26',
caption: 'hey how is my Application ? ',
description: 'hey how is my Application ?',
message: ''
});
});
});
</script>
<script>
FB.init({
appId: '2129405327086578'
});
</script>
What I am missing here?
Tt`s only possible if you have a static IP-adress, and in this case you have to write {your IP}:{port of localhost} to href field

Getting email from LinkedIn Javascript API reliably

Keen to get at the user's email reliably, there doesn't appear to be anything in the API documentation about this from LinkedIn. I have the cod working which grabs the basic profile and I've tried what I can find on the web to get additional fields. But this doesn't return anything. Here is the code:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 11111111111
onLoad: onLinkedInLoad
authorize: true
scope: r_basicprofile
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
var fields = ['firstName', 'lastName', 'emailAddress'];
IN.API.Profile("me").fields(fields).result(onSuccess).error(onError);
}
</script>
and HTML:
<script type="in/Login"></script>
I do not know if it is possible with the current version to return the email or the email is user setting so varies with each user.
You are missing r_emailaddress to the scope:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: 11111111111
onLoad: onLinkedInLoad
authorize: true
scope: r_basicprofile r_emailaddress
</script>
Also be sure you are using the right syntax for the fields:
var fields = ['first-name', 'last-name', 'email-address'];
And finally check in your app setting on LinkedIn developer that you grant r_emailaddress access.

Error validating access token in Hello.js

I am using Hello.js for social login in my website . I am using a standard code that has been provided in the documentation HERE.
my code looks something like this
<script>
//user;
hello.on('auth.login', function (auth) {
// call user information, for the given network
hello(auth.network).api('/me').then(function (r) {
// Inject it into the container
//alert(r.name);
window.user = r.email;
window.im_name = r.name;
if (r.email) ajax1();
});
});
hello.init({
facebook: 'xxxxxxxxxxxxxxxxx',
google: 'xxxxxxxxxxxxxxxxxxxxxx5-q6xxxxxxxxxxxxxxxeusercontent.com',
}, {
redirect_uri: 'http://wstation.yzx.com/',
scope: 'email'
});
</script>
HTML
<button class="btn-fb" onclick="hello( 'facebook' ).login()">Facebook</button>
<button class="btn-google" onclick="hello( 'google' ).login()">Google</button>
Every thing is working fine I am able to login through Facebook and then send the credentials to the server to sign in the user. But after the user sign in . The Ajax1() method is called again and again all the time.
I am trying to read through the Documentation but nothing is helping out
UPDATE
I changed the code into something like this
function connect(x){
hello(x).api("/me").then(function(r){
window.user = r.email;
window.im_name = r.name;
if (r.email) ajax1();
}, function(e){
alert("Whoops! " + e.error.message );
});
}
and HTML
<button class="btn-fb" onclick="connect('facebook')">Facebook</button>
<button class="btn-google" onclick="connect('google')">Google</button>
Now I am getting error
Whoops! Error validating access token: This may be because the user logged out or may be due to a system error.
as an alert
Please help me if any one had same problem
Thanks in advance
I got it worked Hopefully it helps some one else having the same problem
<script>
function connect(x){
hello(x).login().then(function(r){
hello(r.network).api('/me').then(function(r){
alert('Login');
window.user = r.email;
window.im_name = r.name;
if (r.email) ajax1();
}, function(e){
alert("Whoops! " + e.error.message );
});
});
}
hello.init({
facebook: '2xxxxxxxxxxx4',
google: '3xxxxxxxxx5-qxxxxxxxxxxxxx6k1nunigepmsd3.apps.googleusercontent.com',
twitter: 'Yxxxxxxxxxxxw'
}, {
redirect_uri: 'http://wstation.inmotico.com/',
scope: 'email'
});
</script>
Thanks & Regards

Categories

Resources