FB.login() results in auto-login popup before on-click - facebook-javascript-sdk

I'm developing sns login page.
I use custom login-button and FB.login().
Suddenly, I encounted unsuspected problem that FB.login() resulted in auto-login popup before I click login button..
I do Not want pop-up login window before click the login-button...!!
How can I fix this problem?? Help me..plz....ㅜㅜ
this is my url!
http://sangji.dothome.co.kr/index2.html
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function(){
FB.init({
appId: 'myAppKey',
status: true,
cookie: true,
xfbml: true,
oauth: true,
version : 'v2.5'
});
fbLoginStatus();
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/ko_KR/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fbLoginStatus(){
FB.getLoginStatus(function(response) {
console.log(response);
if (response.status === 'connected') {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
} else {
fblogin();
}
});
}
function fblogin(){
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
} else {
console.log('Authorization failed.');
}
},{ //permissions
scope: 'email'
});
}
</script>
<img src="fb_bt.png">
</body>
</html>

You are calling 'fblogin' in the callback to getLoginStatus - this in turn is calling FB.login which is based on opening a popup.

Related

YouTube iFrame API “setPlaybackQuality” not working

YouTube iFrame API “setPlaybackQuality” not working.i want to change video qulity to lowest.but i cant change it by the api.i used player.setPlaybackQuality('small').it not worked.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<button id="change_quality">Change Quality</button>
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: '6LV3JdR5aZw',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
$("#change_quality").click(function() {
event.target.playVideo();
var d=player.getPlaybackQuality()
console.log("before");
console.log(d);
player.setPlaybackQuality('small')
var v=player.getPlaybackQuality()
console.log("after");
console.log(v);
});
}
}
</script>
</body>
</html>
it is not working in youtube demo also
Demo

Facebook login with JS

I'm trying to get a login via Javascript SDK from Facebook.
I just have never done something like that.
So this is my source code:
<html>
<head>
</head>
<body>
<script type="text/javascript">
window.fbAsyncInit=function(){
FB.init({
appId : '1234567890',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('Logged in.');
}
else {
console.log('Logging in...');
FB.login();
}
});
</script>
<input type="button" onClick="FB.getLoginStatus();" value="Login" />
</body>
</html>
But sadly this is doing... nothing :(
There is nothing I can see in the console and nothing displayed (even if I push the Login-Button)
Maybe someone could help me?!
Best regards,
Kartilia

Facebook login dialog doesn't close using javascript SDK

I've tried to do the facebook login using FB Javascript SDK.
After login doesn't close the login window only in opera browser.
How can i fix this problem?
I've tried following source code:
(on-line in this website - LINK)
<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '101103500012652', // App ID
channelUrl: '//www.milujse.cz/app/channel.html', // Channel File
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
} else {
}
});
};
(function(d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
}
function loginFB()
{
FB.login(function(response) {
if (response.authResponse) {
testAPI();
} else {
}
});
}
function logoutFB()
{
FB.logout(function(response) {
});
}
</script>
<input type="button" value="Login" onclick="loginFB();
return false;" />
<input type="button" value="Logout" onclick="logoutFB();
return false;" />
</body>
</html>
Have you considered checking the browser and if it's Opera using the other way to connect with facebook, I mean with oauth you can redirect the whole page to the facebook login page instead of using a popup and so you wont have the problem of not being able to close the popup.
The link to the whole page si something like
"https://graph.facebook.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http:YOUR_CALLBACK-URL&scope=WHAT_YOU_WANT"
There seems to be a bug in Opera in that Opera doesn't support the window.close() function on windows under some curcumstances.
This is referred to at javascript:window.close() and Opera as well as at https://bugzilla.mozilla.org/show_bug.cgi?id=190515 where this is listed as a bug.
It seems the window.closed() event is buggy too in Opera, as per http://dev.vaadin.com/ticket/5687
For example programming browser independent login/logout logic on closing the browser is hard to implement in consequence.
Checked using code below and setting the breakpoint at setUser(null)
package com.example.vaadintests;
import com.vaadin.Application;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;
public class VaadintestsApplication extends Application
{
#Override
public void init()
{
final Window rootWindow = new Window();
setMainWindow(rootWindow);
rootWindow.addListener(new CloseListener()
{
#Override
public void windowClose(CloseEvent e)
{
setUser(null);
}
});
}
}

blank window with query of permissions

I use js sdk for login my site with facebook. If user go to my site first time and try login, it work fine. If user is logged into facebook and go to my site, it work fine too. But if user is logged out from facebook and my site and go to my site after click login button he see popup window and input their email and pass for facebook. After he click login it show blank popup window with this url.
I can't understand why it request permission if facebook know that this user is authorized for my site.
here is my code
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: 189221317879406, status: true, cookie: true, xfbml: true, oauth:true });
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
function loginWithFacebook(){
FB.login(function(response) {
if (response.authResponse) {
//FB.api('/me', function(response) {alert(response.name);});
window.location.href='http://mysite.com/home/';
}
},
{scope: 'user_photos,friends_photos,user_birthday,friends_birthday,user_education_history,friends_education_history,user_location,friends_location,user_relationships,friends_relationships,user_work_history,friends_work_history'});
}
</script>
<a href="#" onclick="loginWithFacebook()">
<img src="/files/images/facebook-login-button.png" style="width: 90px; height: 90px;"></a>
</body>
I was wrong in code. There neccessary add option - channelURL: '//site.com/channel.php'
http://developers.facebook.com/docs/reference/javascript/#channel

Using Fb.ui feed method not showing message nor user_prompt_message at all using default messages

Hi I am new to facebook development, and would like to post a feed using this code below, but the message nor the user_message_prompt do not appear in the text box. Do I need to set something in my application to allow this. All I get is default messages.
I tried the 2 methods below, and both of them do not show the message nor user_message_prompt message.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title></title>
</head>
<body>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: "174009502722096", status: true, cookie: true, xfbml: true });
function postToFeed() {
var publish = {
method: 'feed',
message: 'Martin Okello presents share',
caption: 'Visit MartinLayooinc',
description: (
'Martin Okello, aka the medallion presents his application'
),
link: 'http://www.martinlayooinc.co.uk',
picture: 'http://www.martinlayooinc.co.uk/topImages/bigMedallion.jpg',
user_message_prompt: 'Share MartinLayooinc Software with friends!'
};
FB.ui(publish,
function(response)
{
alert('MartinLayooInc has been posted!!')
});
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
<!--from here-->
<div id="fb-root">
<p>
<a onclick='postToFeed(); return false;'><img src="topImages/facebook_button.png" style="height:20px; width:80px;" />
</a>
</p>
<p id='msg'>
</p>
</div>
</body>
</html>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '174009502722096', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
login();
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
logout();
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
</script>
I believe they are both deprecated. The message parameter is now ignored and I didn't see the other parameter in the documentation. Apparently, Facebook wants users to put their own message into the text field rather than be forced or prompted. Check out the main info page for it here:
https://developers.facebook.com/docs/reference/javascript/FB.ui/
and the detailed page here:
https://developers.facebook.com/docs/reference/dialogs/feed/
Scroll to the bottom and you'll see the supported parameters. Hopefully it's not a game changer for you.
You should do something like this
window.fbAsyncInit = function() {FB.init({
appId: '{YOUR APP ID}',
xfbml: true,
version: 'v2.1'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function share_prompt() {
FB.ui({
method: 'feed',
name: 'Your App Name',
link: 'https://example.com',
picture: 'http://example.com/img/fbicon.jpg',
caption: 'Your Caption here',
description: 'some sort of your own description',
message: 'Your Message goes here mate'
});
}
Then call the function like below;
<div>Click to open your dialog </div>