How to use facebook token from cookie? - facebook

I can get facebook access token on client side of asp.net mvc application with method FB.getLoginStatus()
The token:
EAAFjVDcBGp4BABSnPzvjeR0ZCqEHExSRIGtvEIMPZCZABh****fk03WZCg10xaPJUs3ZCZAMTnP8
It's set token to cookies. I want to access it on server side, but on server I get it:
Kk9fbM-3d8ih4SpCfMddsj23BW2bqwPlll9LLs8ZYUE.eyJh****IjEwNzI4NDM4NjQ0OTI5MiJ9
Why? What should I do to get token from cookie?
UPDATED
Client code:
function checkLoginState() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected')
return;
FB.login();
});
}
window.fbAsyncInit = function() {
FB.init({
appId: #ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId],
cookie : true,
xfbml : true,
version : 'v2.8'
});
};
(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'));
Server code:
var userToken = HttpContext.Current.Request.Cookies[String.Concat("fbsr_", ConfigurationManager.AppSettings[AppParameterKey.FbApplicationId])].Value

The cookies doesn't contains access_token
After a day I founded solution here:
Problem getting access_token after migrating to OAuth 2.0

Related

How to get the PSID after user clicked the SEND-TO-MESSENGER button?

This is my code:
window.fbAsyncInit = function() {
FB.init({
appId: "xxx",
xfbml: true,
version: "v2.6"
});
FB.Event.subscribe('send_to_messenger', function(response) {
// callback for events triggered by the plugin
console.log('inside the send_to_messenger');
if ( response.event == 'clicked' ) {
};
});
};
(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'));
So now, how do I get the PSID of the user ?
You need to subscribe to the messaging_optins webhook event. When the send to messenger button is clicked, you should get the PSID in sender.id prop of the event.

Facebooks OAuth dialog doesn't close properly in IE 11

I'm using FB Client Api for Oauth authentication
All necessary data after login is recieved while authentication dialog becomes blank and doesn't close after successfull authentication. This behavior is only specific for IE 11. The rest of browsers close Oauth dialog successfully.
Here is init code for FB SDK:
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
},
This is my init code for FB Login
function fbAsyncInit() {
FB.init({
appId: options.applicationId, // App ID
status : true,
xfbml : true
});
FB.getLoginStatus( callback );
}
window.fbAsyncInit = window.fbAsyncInit || fbAsyncInit;
And the last but not least: authorization function
authorize = function() {
var dfd = new $.Deferred();
FB.Event.subscribe( "auth.authResponseChange", function( response ) {
if ( response.status === "connected" ) {
dfd.resolve();
return;
} else {
FB.login(function() {
dfd.resolve();
});
}
});
FB.getLoginStatus(function( response ) {
if ( response && response.status === "connected" ) {
dfd.resolve();
return;
}
FB.login();
});
return dfd.promise();
};
Once again - I recieve all necessary events, problem is that dialog doesn't close after successfull authentication.

Facebook app is just posting content on my wall?

I have created a Facebook app which will share a link to users wall
but the issue is the link is posted on my wall but not on any other user's wall
i have put on live link Link to post on wall app
the code of app that will post on users wall is given below is there anything i need to approve it from the facebook or is there any mistake in my code please i need a real help any one could do ?
waiting for your kind response i am new to the Facebook API
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: '763390233734216', // App ID from the app dashboard
//channelUrl : '//local.facebook-test/channel.html', // Channel file for x-domain comms
status: true, // Check Facebook Login status
xfbml: true, // Look for social plugins on the page
oauth: true // Enable oauth authentication
});
// Additional initialization code such as adding Event Listeners goes here
FB.login(function(response) {
if (response.authResponse) {
console.log(response.authResponse.accessToken);
var params = {};
params['name'] = 'Seasons Canola';
params['description'] = 'Description';
params['link'] = 'http://vimeo.com/99708842';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'public_profile,email,publish_actions'
});
};
// Load the SDK asynchronously
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

Facebook pagetab error 500

I have created a Facebook Page Tab. Everything works as expected, the tab can be added to a user's page, they see an Add Page Tab Dialog, etc.
It doesn't work however, when someone is currently "Using Facebook as" a page that they manage. Looking at Chrome developer tools I see an HTTP 500 internal server error.
To recreate this:
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'XXXXXXXXXXXXXXXX',
xfbml: true,
version: 'v2.0',
cookie: true
});
};
(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 init() {
console.log("go!");
FB.ui({
method: 'pagetab',
redirect_uri: 'https://www.somedomain.com/widget/?id=3280',
});
}
setTimeout(function () {
init();
}, 2000);
</script>
I'm at a complete loss, any suggestions are greatly welcomed.

Access denied while redirecting back to application

This is my implementation of facebook login functionality using Facebook SDK.
<script type="text/javascript">
window.fbAsyncInit = function () {
// Initialize the SDK upon load
FB.init({
appId: '1xxxxxxxxxxxx', // App ID
channelUrl: '//' + window.location.hostname + '//Home/Index',
scope: 'id,name,gender,user_birthday,email,first_name,last_name,access_token',
status: true,
cookie: true,
xfbml: true
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', OnLogin);
};
// This method will be called after the user login into facebook.
function OnLogin(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
$('#AccessToken').attr('value', access_token);
$("#AuthenticatedWithFacebook").attr("value", true);
FB.api('/me', LoadValues);
}
else {
$("#AuthenticationToken").removeAttr('value');
$("#AuthenticatedWithFacebook").attr("value", false);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if (me.id) {
$("#UserId").attr("value", me.id);
$("#AuthenticationToken").attr("value", "facebook/" + me.id);
$("#FirstName").attr("value", me.first_name);
$("#LastName").attr("value", me.last_name);
$("#EmailAddress").attr("value", me.email);
}
}
</script>
<script>(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/all.js#xfbml=1&appId=1xxxxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Login Pop-Up works just fine but after logging in I'm getting following exception:
Exception was thrown at line 38, column 184 in http://static.ak.fbcdn.net/rsrc.php/v2/yQ/r/Yax99g-1J46.js
0x80070005 - JavaScript runtime error: Access is denied.
I'm testing here on localhost (http://localhost:59777/) which I have configured in my Facebook application as well.