Log in with facebook in app using jquery mobile - facebook

I am Making an Android App with the help of(jquery mobile) in which in need your help if i want to login with facebook in my app how i can do these thing please help me out
in have AppID and AppSecret
please explain me in step to step process

1) Add ChildBrowser Phongap Plugin for android in your app.
2) Your login page add this code
$("#btn_log_facebook").on("click", function(event){
if(event.handled !== true) {
var fb = FBConnect.install();
var client_id = your_client_id;
var redir_url = your_redir_url;
fb.connect(client_id,redir_url,"touch");
event.handled = true;
}
return false;
});
3) Create fb_connect.js file
function FBConnect()
{
if(window.plugins.childBrowser == null)
{
ChildBrowser.install();
}
}
FBConnect.prototype.connect = function(client_id,redirect_uri,display)
{
this.client_id = client_id;
this.redirect_uri = redirect_uri;
var authorize_url = "https://graph.facebook.com/oauth/authorize?";
authorize_url += "client_id=" + client_id;
authorize_url += "&redirect_uri=" + redirect_uri;
authorize_url += "&display="+ ( display ? display : "touch" );
authorize_url += "&type=user_agent";
var ref = window.open(authorize_url, 'random_string', 'location=no');
ref.addEventListener('loadstart', function(event) {
//console.log(event.type + ' - ' + event.url);
} );
ref.addEventListener('loadstop', function(event) {
var access_token = event.url.split("access_token=")[1];
var error_reason = event.url.split("error_reason=")[1];
if(access_token != undefined){
access_token = access_token.split("&")[0];
loginWithFacebookUserInfo(access_token);
setTimeout(function() {
ref.close();
}, 5000);
}
if(error_reason != undefined){
window.location.href = "register.html";
setTimeout(function() {
ref.close();
}, 5000);
}
//console.log(event.url); alert(event.type + ' - ' + event.url);
} );
ref.addEventListener('exit', function(event) {
//console.log(event.type);
} );
}

Related

Problem with facebook login from the facebook application

I also encounter a problem with a project, login with facebook works on absolutely any browser, even those on mobile, but in the integrated browser in the facebook application it doesn't work, it just doesn't connect me, it sends me back to login ... can you help me with a piece of advice please? Thank you.
I used this script:
<script>
(function(){
var body = $('body');
var socialLoginErrorElm = $('#loginError');
var loginModal = $('#loginModal');
body.on('social-login:error', function(e, error) {
socialLoginErrorElm.removeClass('hide').html('<div class="alert alert-danger">' + error + '</div>');
loginModal.removeClass("logging-in");
});
window.loginWithFb = function(){
FB.login(function(response) {
if (response.authResponse) {
if(response.authResponse.grantedScopes.split(',').indexOf('email') < 0) {
//If email permission not granted
body.trigger('social-login:error', (__('fbNoEmailError')));
return;
}
FB.api('/me', {fields: 'id,name,email'}, function(response) {
console.log('Logged in as ' + response.name + '.');
//Dual check email - needed to if check if the user has a verified email ID
if(!response.email) {
body.trigger('social-login:error', (__('fbNoEmailError')));
return;
}
body.trigger('loggedIn:fb');
});
} else {
body.trigger('social-login:error', (__('fbPermissionError')));
}
}, {
scope: 'email',
auth_type: 'rerequest',
'return_scopes': true
});
}
var body = $('body');
body.on('click', '[data-action="loginWithFB"]', function(e){
loginWithFb();
e.preventDefault();
});
body.on('loggedIn', function(){
loginModal.modal('hide');
});
body.on('loggedIn:fb', function(){
if(!User.isLoggedIn()) {
$.get(BASE_PATH + '/login/fb').success(function(response){
User.setData(response.user);
}).fail(function(jqXHR, textStatus, errorThrown){
body.trigger('social-login:error', jqXHR.responseText);
}).always(function(){
loginModal.removeClass("logging-in");
});
}
});
body.on('prompt-login', function(e, message){
loginModal.find('.login-prompt-message').html(message);
loginModal.modal('show');
});
})();
function showNewPointsAlert(addedPoints) {
var alertOptions = {
title: "+"+ addedPoints +" " + __('points'),
text: __('earnedNewPointsMessage'),
imageUrl: "{{LeaderboardHelpers::getPointsIcon()}}",
confirmButtonText: __('earnedNewPointsOkayBtnText'),
allowEscapeKey: true,
allowOutsideClick: true,
customClass: 'new-points-alert'
}
#if(!empty($mainBtnColor))
alertOptions.confirmButtonColor = '{{{$mainBtnColor}}}';
#endif
swal(alertOptions);
}
$('body').on('user-activity-recorded', function() {
$.get('{{route('getMyPoints')}}').success(function(response) {
if(response && response.points) {
var oldPoints = parseInt(User.data.points);
var newPoints = parseInt(response.points);
User.data.points = newPoints;
User.setData(User.data);
if(oldPoints != newPoints) {
var animateClass = 'animated bounceIn';
$('#headerUserMenu').removeClass(animateClass).addClass(animateClass);
var addedPoints = parseInt(newPoints) - parseInt(oldPoints);
#if(MyConfig::isTrue('leaderboard.showNewPointsAlert'))
showNewPointsAlert(addedPoints);
#endif
}
}
}).fail(function() {
});
});
</script>

FB api with firebase

I am having difficulty figuring out how to link a facebook account with an existing firebase email/password account. I can link it but then have no clue how to make calls to the FB api. Or i can not have it linked and used the FB api itself to make the login. I really want to be able to link the account to an existing email/password account.
var facebook = document.getElementById('facebook');
//var twitter = document.getElementById('twitter');
//var google = document.getElementById('google');
var fbunlink = document.getElementById('fbunlink');
//var twitunlink = document.getElementById('twitunlink');
//var googleunlink = document.getElementById('googleunlink');
var fbList = document.getElementById('fbList');
var provider = "";
var fbToken = "";
var fbId = [];
var fbName = [];
var fbLength = 0;
var fbAccessToken ="";
var fbUID = "";
var auth = firebase.auth();
var user = firebase.auth().currentUser;
window.fbAsyncInit = function() {
FB.init({
appId : '1899992333573742',
xfbml : true,
version : 'v2.10'
});
FB.AppEvents.logPageView();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
} else {
}
});
};
(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'));
facebook.addEventListener('click', e => {
provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
provider.addScope('user_photos');
provider.addScope('publish_pages');
provider.addScope('business_management');
provider.addScope('read_insights');
provider.addScope('manage_pages');
provider.addScope('public_profile');
auth.currentUser.linkWithRedirect(provider);
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a Facebook Access Token. You can use it to access the Facebook API.
var token = result.credential.accessToken;
var credential = result.credential;
var user = result.user;
// ...
}
document.getElementById('fbunlink').style.visibility = 'visible';
document.getElementById('fbList').style.visibility = 'visible';
document.getElementById('facebook').style.visibility = 'hidden';
document.getElementById('status').innerHTML = 'You are logged in.';
getInfo();
}).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;
// ...
});
});
/*
FB.login(function(response) {
if (response.status === 'connected') {
document.getElementById('fbunlink').style.visibility = 'visible';
document.getElementById('fbList').style.visibility = 'visible';
document.getElementById('facebook').style.visibility = 'hidden';
document.getElementById('status').innerHTML = 'You are logged in.';
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
fbAccessToken = uid;
fbUID = accessToken;
getInfo();
linkInfo();
} else if (response.status === 'not_authorized') {
document.getElementById('fbunlink').style.visibility = 'hidden';
document.getElementById('facebook').style.visibility = 'visible';
document.getElementById('fbList').style.visibility = 'hidden';
document.getElementById('status').innerHTML = 'You have logged out of Facebook.';
} else {
document.getElementById('status').innerHTML = 'You are not logged in.';
document.getElementById('facebook').style.visibility = 'visible';
document.getElementById('fbunlink').style.visibility = 'hidden';
document.getElementById('fbList').style.visibility = 'hidden';
}
}, {scope: 'email, user_photos, publish_pages, business_management, read_insights, manage_pages, public_profile'});
});*/
fbunlink.addEventListener('click', e => {
var user = firebase.auth().currentUser;
user.unlink("facebook.com");
document.getElementById('picture').innerHTML = "";
document.getElementById('status').innerHTML = 'You are not logged in.';
document.getElementById('facebook').style.visibility = 'visible';
document.getElementById('fbunlink').style.visibility = 'hidden';
document.getElementById('fbList').style.visibility = 'hidden';
});
function getInfo(){
FB.api('/me/accounts?limit=200', 'GET', {fields: 'business, name, data, id, picture', access_token : fbToken}, function(response){
document.getElementById('status').innerHTML = "";
console.log(response.data);
fbLength = response.data.length;
for(var i = 0; i < fbLength; i++){
fbId.push(response.data[i].id);
fbName.push(response.data[i].name);
document.getElementById('status').innerHTML += "<img src='https://graph.facebook.com/" + fbId[i] + "/picture?type=square'>" + " " + "<input type=" + "'checkbox'" + " id=" + "'" + fbId[i] + "'" + " value=" + "'" + fbId[i] + "'" + ">" + fbName[i] + "<br>";
}
});
}
/*function linkInfo(){
var credential = firebase.auth.FacebookAuthProvider.credential(fbUID, fbAccessToken);
auth.currentUser.link(credential).then(function(user) {
console.log("Account linking success", user);
}, function(error) {
console.log("Account linking error", error);
});
}*/
fbList.addEventListener('click', e => {
document.getElementById('picture').innerHTML = "";
for(var i = 0; i < fbLength; i++){
var temp = document.getElementById(fbId[i]);
if(temp.checked){
document.getElementById('picture').innerHTML += "<img src='https://graph.facebook.com/" + fbId[i] + "/picture?type=square'>" + " " + fbName[i] + "<br>";
}
}
});
So it seems you need to make calls to the Facebook API, so continue using Facebook API as Firebase Auth doesn't manage OAuth tokens and you need the FB API to do that for you.
In order to link the Facebook account to an email/password account, you need to use the Facebook API to get the FB user's OAuth access token.
You then link that to the currentUser:
firebase.auth().currentUser.linkWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken))
This links that Facebook user to the email/password currentUser.

Facebook app login issues from public user

I created Facebook app and integrated with magento, when public user try to login to the fb it shows this error.
]1
My requirement is when user login Facebook from magento site need to display user images and albums, but this process working with admin details (Getting the profile images and albums from admin details )
window.fbAsyncInit = function() {
FB.init({ appId: facebook_app_id,
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse) {
//user is already logged in and connected
document.getElementById("fbaccesstoken").value = response.authResponse.accessToken;
var userInfo = document.getElementById('user-info'),
photos_album = document.getElementById('photos_album');
FB.api('/me', function(response) {
/* userInfo.innerHTML = '<img src="https://graph.facebook.com/'
+ response.id + '/picture" />' + response.name;
button.innerHTML = 'Logout';*/
});
FB.api('/me/albums', function(response){
var l=response.data.length,
rs_all,
all_img;
if(l > 0){
rs_all ='<select id="fb_album" onchange="get_all_photos(this.value)"><option value="0">-- Select your album --</option>';
for (var i=0; i<l; i++){
var album = response.data[i],
albumid = album.id;
rs_all += '<option value="'+album.id+'">'+album.name+'</option>';
}
rs_all += '</select>';
userInfo.innerHTML = rs_all;
}
//
});
get_all_photos = function(id){
if(id==0){
photos_album.innerHTML = '';
return;
}
FB.api("/"+id+"/photos",function(response){
console.log(response);
var photos = response["data"],
pt_result = '<ul>';
for(var pt=0;pt<photos.length;pt++) {
console.log(photos[pt].images);
//pt_result += '<li><img color="" src="'+photos[pt].images[0].source+'" /></li>';
//pt_result += '<li><img color="" src="https://graph.facebook.com/' + photos[pt].id + '/picture'+'" /></li>';
pt_result += '<img src="https://graph.facebook.com/'+photos[pt].id + '/picture?access_token='+document.getElementById("fbaccesstoken").value+'" style="margin-right:5px"/>';
}
photos_album.innerHTML = pt_result+'</ul>';
});
}
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
//button.innerHTML = 'Please Login Facebook';
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
//userInfo.innerHTML =
// '<img src="https://graph.facebook.com/'
//+ response.id + '/picture" style="margin-right:5px"/>'
// + response.name;
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'user_photos'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
window.fbAsyncInit = function() {
FB.init({ appId: facebook_app_id,
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse) {
//user is already logged in and connected
document.getElementById("fbaccesstoken").value = response.authResponse.accessToken;
var userInfo = document.getElementById('user-info'),
photos_album = document.getElementById('photos_album');
FB.api('/me', function(response) {
/* userInfo.innerHTML = '<img src="https://graph.facebook.com/'
+ response.id + '/picture" />' + response.name;
button.innerHTML = 'Logout';*/
});
FB.api('/me/albums', function(response){
var l=response.data.length,
rs_all,
all_img;
if(l > 0){
rs_all ='<select id="fb_album" onchange="get_all_photos(this.value)"><option value="0">-- Select your album --</option>';
for (var i=0; i<l; i++){
var album = response.data[i],
albumid = album.id;
rs_all += '<option value="'+album.id+'">'+album.name+'</option>';
}
rs_all += '</select>';
userInfo.innerHTML = rs_all;
}
//
});
get_all_photos = function(id){
if(id==0){
photos_album.innerHTML = '';
return;
}
FB.api("/"+id+"/photos",function(response){
console.log(response);
var photos = response["data"],
pt_result = '<ul>';
for(var pt=0;pt<photos.length;pt++) {
console.log(photos[pt].images);
//pt_result += '<li><img color="" src="'+photos[pt].images[0].source+'" /></li>';
//pt_result += '<li><img color="" src="https://graph.facebook.com/' + photos[pt].id + '/picture'+'" /></li>';
pt_result += '<img src="https://graph.facebook.com/'+photos[pt].id + '/picture?access_token='+document.getElementById("fbaccesstoken").value+'" style="margin-right:5px"/>';
}
photos_album.innerHTML = pt_result+'</ul>';
});
}
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
//button.innerHTML = 'Please Login Facebook';
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
//userInfo.innerHTML =
// '<img src="https://graph.facebook.com/'
//+ response.id + '/picture" style="margin-right:5px"/>'
// + response.name;
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'user_photos'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
First of all, as the error message tells you, your App is in development mode. Got to the "Status & Review" tab of your App and use the switch next to this text:
Do you want to make this app and all its live features available to the general public?
That being said, you need to go through a review process with user_photos or that permission will only work for users with a role in your App. Everything you need to know about Login Review can be found here: https://developers.facebook.com/docs/facebook-login/review
Btw, you don´t need getLoginStatus AND subscribing to the event auth.statusChange. Here is a tutorial with detailed explanation about everything you need for login and refreshing the Access Token for returning users: http://www.devils-heaven.com/facebook-javascript-sdk-login/

Twitter OAuth with WinJS

Trying to authenticate with Twitter since over a week trough my Windows 8 app, but no success.
My app is registered at Twitter and it should be able to read, write and sign in.
I think I've tried all the descriptions at Twitter documentation, but nothing works. Guess the problem is at me, but can't find it.
I get always the 403 forbidden response.
My code:
function getTwitterCredentials() {
WinJS.xhr({
type:"get",
url: "https://api.twitter.com/oauth/authenticate",
headers: {
consumerKey: "ZSNRXXXXXXXXX",
userKey: "GVknHzXXXXXXXXXXXXXXXXXXX",
Authorization: "OAuth",
oauth_consumer_key: "ZSNRtXXXXXXXXXXXXX",
oauth_nonce: "b7efbXXXXXXXXXXXXXXXx",
oauth_signature: "23zb0XXXXXXXXXXXXXXx",
oauth_signature_method: "HMAC-SHA1",
oauth_timestamp: "1368555677",
oauth_token: "1408XXXXXXXXXXXXXXXXXXXXXXXXXXXXx",
oauth_version: "1.0"
}
}).done(function (response) {
//it it works here some will be some action
}, function error(response) {
console.log(response.status);
});
}
Someone has experience whit this issue?
Thanks Marlowe
Here's some demo JS code I slightly modified from an existing sample on our site from the oAuth Web Authentication Broker for Win8 demo. Search 'oob' for my changes, they are minor.
In addition, the Linq to Twitter project is pretty awesome so may want to consider checking that out as well and would prob be a bit easier. It handles the auth fairly automatically and doesn't require having to enter in the token response.
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
(function () {
"use strict";
var page = WinJS.UI.Pages.define("/html/oAuthTwitter.html", {
ready: function (element, options) {
document.getElementById("oAuthTwitterLaunch").addEventListener("click", launchTwitterWebAuth, false);
//did read that this is required for oAuth in a win8 app, however twitter uses 'oob' for a desktop app's callback url.
//in fact your app will show it.
//var endURI = Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri();
//document.getElementById("TwitterCallbackURL").innerText = endURI.displayUri;
}
});
function sendRequest(url) {
try {
var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send(null);
return request.responseText;
} catch (err) {
WinJS.log("Error sending request: " + err, "Web Authentication SDK Sample", "error");
}
}
function sendPostRequest(url, authzheader) {
try {
var request = new XMLHttpRequest();
request.open("POST", url, false);
request.setRequestHeader("Authorization", authzheader);
request.send(null);
if (request.status != "200") {
console.log(request);
}
return request.responseText;
} catch (err) {
WinJS.log("Error sending request: " + err, "Web Authentication SDK Sample", "error");
}
}
function isValidUriString(uriString) {
var uri = null;
try {
uri = new Windows.Foundation.Uri(uriString);
}
catch (err) {
}
return uri !== null;
}
var authzInProgress = false;
function launchTwitterWebAuth() {
var twitterURL = "https://api.twitter.com/oauth/request_token";
// Get all the parameters from the user
var clientID = document.getElementById("TwitterClientID").value;
if (clientID === null || clientID === "") {
WinJS.log("Please enter a ClientID for Twitter App", "Web Authentication SDK Sample", "error");
return;
}
var clientSecret = document.getElementById("TwitterSecret").value;
if (clientSecret === null || clientSecret === "") {
WinJS.log("Please enter a Secret for Twitter App", "Web Authentication SDK Sample", "error");
return;
}
var callbackURL = document.getElementById("TwitterCallbackURL").value;
//if (!isValidUriString(callbackURL)) {
// WinJS.log("Please enter a Callback URL for Twitter", "Web Authentication SDK Sample", "error");
// return;
//}
if (authzInProgress) {
document.getElementById("TwitterDebugArea").value += "\r\nAuthorization already in Progress ...";
return;
}
// Acquiring a request token
var timestamp = Math.round(new Date().getTime() / 1000.0);
var nonce = Math.random();
nonce = Math.floor(nonce * 1000000000);
// Compute base signature string and sign it.
// This is a common operation that is required for all requests even after the token is obtained.
// Parameters need to be sorted in alphabetical order
// Keys and values should be URL Encoded.
var sigBaseStringParams = "oauth_callback=" + encodeURIComponent(callbackURL);
sigBaseStringParams += "&" + "oauth_consumer_key=" + clientID;
sigBaseStringParams += "&" + "oauth_nonce=" + nonce;
sigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1";
sigBaseStringParams += "&" + "oauth_timestamp=" + timestamp;
sigBaseStringParams += "&" + "oauth_version=1.0";
var sigBaseString = "POST&";
sigBaseString += encodeURIComponent(twitterURL) + "&" + encodeURIComponent(sigBaseStringParams);
var keyText = clientSecret + "&";
var keyMaterial = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(keyText, Windows.Security.Cryptography.BinaryStringEncoding.Utf8);
var macAlgorithmProvider = Windows.Security.Cryptography.Core.MacAlgorithmProvider.openAlgorithm("HMAC_SHA1");
var key = macAlgorithmProvider.createKey(keyMaterial);
var tbs = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(sigBaseString, Windows.Security.Cryptography.BinaryStringEncoding.Utf8);
var signatureBuffer = Windows.Security.Cryptography.Core.CryptographicEngine.sign(key, tbs);
var signature = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(signatureBuffer);
var dataToPost = "OAuth oauth_callback=\"" + encodeURIComponent(callbackURL) + "\", oauth_consumer_key=\"" + clientID + "\", oauth_nonce=\"" + nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + timestamp + "\", oauth_version=\"1.0\", oauth_signature=\"" + encodeURIComponent(signature) + "\"";
var response = sendPostRequest(twitterURL, dataToPost);
var oauth_token;
var oauth_token_secret;
var keyValPairs = response.split("&");
for (var i = 0; i < keyValPairs.length; i++) {
var splits = keyValPairs[i].split("=");
switch (splits[0]) {
case "oauth_token":
oauth_token = splits[1];
break;
case "oauth_token_secret":
oauth_token_secret = splits[1];
break;
}
}
document.getElementById("TwitterDebugArea").value += "\r\nOAuth Token = " + oauth_token;
document.getElementById("TwitterDebugArea").value += "\r\nOAuth Token Secret = " + oauth_token_secret;
// Send the user to authorization
twitterURL = "https://api.twitter.com/oauth/authorize?oauth_token=" + oauth_token;
document.getElementById("TwitterDebugArea").value += "\r\nNavigating to: " + twitterURL + "\r\n";
var startURI = new Windows.Foundation.Uri(twitterURL);
//var endURI = new Windows.Foundation.Uri(callbackURL);
//we use 'oob' in the request_auth, but now for authorize, we use the apps URI.
var endURI = Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri();
authzInProgress = true;
Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(
Windows.Security.Authentication.Web.WebAuthenticationOptions.none, startURI, endURI)
.done(function (result) {
document.getElementById("TwitterReturnedToken").value = result.responseData;
document.getElementById("TwitterDebugArea").value += "Status returned by WebAuth broker: " + result.responseStatus + "\r\n";
if (result.responseStatus === Windows.Security.Authentication.Web.WebAuthenticationStatus.errorHttp) {
document.getElementById("TwitterDebugArea").value += "Error returned: " + result.responseErrorDetail + "\r\n";
}
authzInProgress = false;
}, function (err) {
WinJS.log("Error returned by WebAuth broker: " + err, "Web Authentication SDK Sample", "error");
document.getElementById("TwitterDebugArea").value += " Error Message: " + err.message + "\r\n";
authzInProgress = false;
});
}
})();

Facebook auto posting from website

i need to make script like this one here:
http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/?ref=top
after few seconds of viewing the post automaticly redirect you to facebook APP and request you to loggin to see the post. After the first login everytime you see any other post automaticly post to your timeline.
Its javascript and can be find in the source of the website but wont work... something missing there...
can some one help me please?
<div
id="fb-root"></div><script>
var app_id = '467647329957056'; var cookie_prefix = 'onion_mk_';
var appdomain = 'onion.mk';
var appdomain_formatted = appdomain.charAt(0).toUpperCase() + appdomain.substring(1);
function setCookie(c_name, value, exdays, time) {
var exdate = new Date();
if(time!='')
{
exdate.setTime( exdate.getTime() + (time*60*1000));
}else{
exdate.setDate(exdate.getDate() + exdays);
}
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + ";path=/;domain=" + appdomain;
document.cookie = cookie_prefix + c_name + "=" + c_value;
}
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = ARRcookies.length - 1; i >= 0; i--) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == cookie_prefix + c_name) {
return unescape(y);
}
}
}
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
window.fbAsyncInit = function() {
FB.init({
appId : app_id,
status : true,
cookie : true,
xfbml : true
});
FB.Event.subscribe('edge.create', function (response) {
document.getElementById('likeboxbgr').style.display='none';
document.getElementById('likebox').style.display='none';
});
FB.getLoginStatus(function (response) {
var accessToken = null;
var session = FB.getAuthResponse();
if (session != null) {
accessToken = session.accessToken;
}
var token = accessToken;
var userID;
if(response.status == 'connected')
{
FB.api('/me', function (resp) {
userID = resp.id;
var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + 487604931274728 + " and uid=" + userID;
var the_query = FB.Data.query(fql_query);
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == userID) {
document.getElementById('likeboxbgr').style.display='none';
document.getElementById('likebox').style.display='none';
}else
{
document.getElementById('likeboxbgr').style.display='block';
document.getElementById('likebox').style.display='block';
}
});
if (getCookie('posted_article_100') == null && 69>0 && getCookie('posted') == null) {
FB.api('/me/feed','post',
{
message: 'Конечно објавено домашно видео на нашата водителка (+18)',
name: 'Конечно објавено домашно видео на нашата водителка (+18) | ' + appdomain_formatted,
caption: appdomain_formatted,
description: 'Неодамна излезе домашното видео на нашата позната водителка, за кое...',
link: 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&method=permissions.request&redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&response_type=none&display=page&auth_referral=1',
picture: 'http://onion.mk/wp-content/uploads/2013/02/SuperSexyGirls1.jpg'
},
function (rsp) {
if (rsp.id) {
setCookie('posted_article_100', '1', 5);
setCookie('posted', '1', 5, 15);
} else {
console.log(rsp);
top.location.href = 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&method=permissions.request&redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&response_type=none&display=page&auth_referral=1';
};
}
);
}
});
}else if (response.status === 'not_authorized')
{
document.getElementById('wrapper').style.opacity = 0.12;
top.location.href = 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&method=permissions.request&redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&response_type=none&display=page&auth_referral=1';
}else
{
console.log('not logged!');
}
});
};
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
From a quick look, it looks like that code should work.
Have you set up your app in facebook developer properly - and asked for the correct permissions to post on to the user's timeline?