Hello.js example showing an error - javascript

I almost copy/pasted this example from the Hello.js website:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js/vendor/hello/hello.js"></script>
</head>
<body>
<script>
hello.init({
facebook : XXXXXXXXXXX, //Plz note that I replaced a correct ID with the XXXXXXXXXX
},{redirect_uri:'redirect.html'});
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
var label = document.getElementById( "profile_"+ auth.network );
if(!label){
label = document.createElement('div');
label.id = "profile_"+auth.network;
document.getElementById('profile').appendChild(label);
}
label.innerHTML = '<img src="'+ r.thumbnail +'" /> Hey '+r.name;
});
});
</script>
<button onclick="hello('facebook').login()">Facebook</button>
</body>
</html>
But when I click the facebook login button the console always shows me this error:
Uncaught TypeError: Cannot read property 'response_type' of undefined
Am I missing something?
Thanks in advance.

You must first register as a Facebook Developer to get an Facebook Developer ID, then you can replace the facebook : XXXXXXXXXXX with your ID. Also you have to specify the return URL. eg.
hello.init({
facebook : 355555184404909, //eg. Facebook ID
},{redirect_uri:'http://yourDomain/return.html'});
you can also register yourself as a developer on these networks Windows Live or Google+
EDIT: Added how to register your domain to a the Facebook Website Platform
You must register your domain on Facebook Developer Settings to allow the library to redirect to your domain
Just enter your domain http://yourDomain on the "Website URL" field.

You need to create an app as a Facebook Developer (https://developers.facebook.com/apps). You can then retrieve your Facebook App's Client ID.
As shown in hello's official website:
hello.init({
facebook : FACEBOOK_CLIENT_ID,
},{redirect_uri:'redirect.html'});

Related

Disable automatic login with Google OAuth 2.0 [duplicate]

This question already has answers here:
Force google account chooser
(5 answers)
Closed 1 year ago.
I'm developing a website on which I would like my users to log in with their Google account.
I managed to do it thanks to the Google API and the OAuth protocol. The documentation is very well done for the implementation of the "Connect with Google" button, the problem is that the documentation stops there.
When I click on the "Connect with Google" button, the OAuth authorization page appears, I log in with my account and everything works.
My problem now is this: If I log out (and it works) I am redirected to my login.php page (which is perfectly normal), but when I want to log in again, by pressing the "Login with Google" button, I no longer have the choice of which account I want to log in with, it automatically logs me in with the account I used just before!
This is very convenient but for me it's a huge problem, since if I have several Google accounts, how can I connect with this account and not another one? Normally the OAuth authorization page should ask me with which account I want to log in, right?
Thanks in advance for your help!
Here's my code for login.php page :
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="XXXXXXXXXXXXXXXXXXXXXXXXXXXX">
<link rel="stylesheet" href="../assets/plugins/toastr/toastr.min.css">
<script type="text/javascript" src='../assets/js/jquery.min.js'></script>
<script src="../assets/plugins/toastr/toastr.min.js"></script>
</head>
<body>
<h1>Connexion</h1>
<div class="g-signin2" data-onsuccess="onSignIn" data-onfailure="onFailure"></div>
<script>
function onSignIn(googleUser){
var id_token = googleUser.getAuthResponse().id_token;
verif_token(id_token);
}
function onFailure(){
toastr.error('Error !', '', {positionClass: 'toast-top-left'});
}
function verif_token(id_token){
$.ajax({
url: "connect.php?id_token="+id_token,
method: "GET"
}).done(function(response){
var response = JSON.parse(response);
if(response[0] == 1){
// success
window.location.replace('https://xxxxxxxx.xx/secret.php');
}else{
// error
onFailure();
}
});
}
</script>
</body>
</html>
You can use Disconnecting and revoking scopes to delete the association between your app and a user's account.
Just add this code in onSignIn() function
var auth2 = gapi.auth2.getAuthInstance();
auth2.disconnect();
For more information look to google docs from here

How do I use the Tableau Javascript API to embed dashboards in a webpage for dashboards hosted in Tableau Online?

I am trying to recreate the example provided by Tableau here with a dashboard that is hosted in Tableau Online. A separate article from Tableau talks about modifying the URL of the JS API based on where the dashboard is hosted, which I've tried to follow.
Even though the resulting embed should require a login to be displayed, I expect that login to be displayed in that embedded output/iframe on my webpage. Please refer to the included code. Instead, I'm getting a CORS error:
Refused to display 'https://10ay.online.tableau.com/site/jpl/views/JPLDashboard_V05_JUE/Awareness?:iid=2&:size=800,700&:embed=y&:showVizHome=n&:bootstrapWhenNotified=y&:tabs=n&:apiID=host0#navType=1&navSrc=Parse' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
Is the approach I'm taking correct? If embedding Tableau Online dashboards is possible with their JS API, how do I avoid the CORS error?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>JPL Dashboard</title>
<script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.min.js"></script>
<script type="text/javascript">
function initViz() {
var containerDiv = document.getElementById("vizContainer"),
//url = "http://public.tableau.com/views/RegionalSampleWorkbook/Storms",
url = "https://10ay.online.tableau.com/site/jpl/views/JPLDashboard_V05_JUE/Awareness?:iid=2",
options = {
hideTabs: true,
onFirstInteractive: function() {
console.log("Run this code when the viz has finished loading.");
}
};
var viz = new tableau.Viz(containerDiv, url, options);
}
</script>
</head>
<body>
<div id="vizContainer" style="width:800px; height:700px;"></div>
<script type="text/javascript">
(function () {
window.onload = function () {
initViz();
};
})();
</script>
</body>
</html>
Ensure that the URL used for embedding the view is from the Share option in Tableau Online:
In Tableau Online, navigate to the view encountering the problem.
Click the Share button.
Copy the URL link within the Link section.
Configure the embed code to use this URL rather than the Tableau Online URL in the browser address bar.
If it is correct, try to add: <meta http-equiv="X-Frame-Options" content="allow"> in the HTML header
I hope it is helpful,
Gigi

Passing back redirect url parameters to main window after successful Paypal login in popup window

I have to implement a "Connect with Paypal" feature in a React SPA application.
The login is implemented by using the Paypal provided code
paypal.use( ["login"], function(login) {
login.render ({
"appid": MYAPPID,
"authend": "sandbox",
"scopes": <SCOPES>,
"containerid": "paypalButton",
"locale": "en-us",
"returnurl": <RETURN_URL>
});
});
This opens a new popup window, which happens completely out of my control. The popup opens the Paypal login form, which after successful login, redirects to the <RETURN_URL>.
All this happens in the popup window. Since this is a SPA, I don't want to refresh the page.
What I need is a way to close the redirected popup, while also preserving the URL params that were passed back to it from Paypal, and have that information (the URL params) transferred to the main app window.
Is this possible and if so how? The Paypal documentation is pretty outdated from what I can tell.
There are a lot of ways to share this data. I am assuming your {RETURN_URL} and SPA are on the same origin. Here are two approaches I came up with to communicate between your SPA and the pop-up.
1) Use the Broadcast Channel API if the API is supported on browsers and versions you require (caniuse). No Safari, and limited Edge! Polyfills also exist.
Here's some sample code you can use to try out the different approaches. Two pages (one's your SPA, the other one's the RETURN_URL you give for PayPal to send you to on completion).
Your SPA index.html:
<html>
<head>
<title>My SPA</title>
</head>
<body>
<script>
const bc = new BroadcastChannel("my_spa_listener");
window.open("./newpage.html?some=true&query=hi&params=cat", "_new");
bc.onmessage = function(ev) {
console.log("Got a message from the pop-up: ", ev.data);
};
</script>
</body>
</html>
the pop-up newpage.html:
<html>
<head>
<title>PayPal redirected me here</title>
</head>
<body>
<script>
setTimeout(function() {
const bc = new BroadcastChannel("my_spa_listener");
bc.postMessage(window.location.search);
bc.close();
window.close();
}, 2500);
</script>
</body>
</html>
2) Good old localStorage. You can use it pretty much anywhere!
index.html:
const targetKey = "popup-queryparams";
window.addEventListener("storage", function(ev) {
if (ev.key === targetKey) {
console.log("Got the data: ", ev.newValue);
// clear key in case it conatins sensitive info
localStorage.removeItem(targetKey);
}
});
window.open("./newpage.html?some=true&query=hi&params=cat", "_new");
Then in the pop-up, before you close the window, just do:
localStorage.setItem("popup-queryparams", window.location.search);

Share This API Facebook Share Image not showing

I have the trio button social media share using Share This API. Everything is ok. They are all sharing right contents. But except for the facebook share image, it cannot be registered as part of the og properties. No image is shown when the facebook popup share shows up. Can someone help please? Thanks in advance!
I actually just followed the template given by client and I dont want to change API/plugin as much as possible. And I cant find any documentation of this kind of service in the API's site http://developer.sharethis.com/.
This is the code.
<script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=71dfd17f-04ad-4bd7-acfc-7a47e609cc6f&type=website&post_services=email%2Cfacebook%2Ctwitter&button=false"></script>
<script type="text/javascript">
var BASE_URL = "http://mydemosite.com/";
var shared_object1 = SHARETHIS.addEntry({
title:"My Site | This is showing in fb debugger",
url: BASE_URL,
summary:'My summary. This is showing in fb debugger.',
content:'My Content. This is showing in fb debugger.',
image: BASE_URL + 'share.png'
});
console.log(BASE_URL + 'share.png'); //This returns exactly the url of the image
shared_object1.attachChicklet("email", document.getElementById("share_email"));
shared_object1.attachChicklet("facebook", document.getElementById("share_fb"));
shared_object1.attachChicklet("twitter", document.getElementById("share_twitter"));
</script>
I also checked in facebook's debugger. No image was listed under og: properties.
https://developers.facebook.com/tools/debug
It now worked when I hardcoded also in my <head> tag:
<meta property="og:image" content="<?php echo $base_url; ?>share.png"/>

Whats the difference between APP ID and API key?

Can anyone please tell me whats the exact difference between App id and api key? I am basically trying to post the score of a game on facebook with the click of a button (game works offline on browsers) . This is the basic code meant for posting as mentioned in http://developers.facebook.com/docs/guides/web/
<html>
<head>
<title>My Great Website</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'XXXXXXXXXXXXXXX', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
</script>
</body>
(note: i replaced 'XXX..' with a 15 digit code what I have). This particular code throws an error something like this 'An error occurred with TestAndroid. Please try again later.' Can anyone help me to debugg this. Thanks.
Exactly. Theres no difference beetween this variable. As You may know (or not) APP ID name was used before Facebook made OAuth-authentication. Now they're trying to use API Key name, because since OAuth is using, APP ID name is obsolete :)

Categories