API Error Description: Session key invalid or no longer valid (error 102) - facebook

I cant figure out why facebook publish is not working on this site
I get
API Error Code: 102
API Error Description: Session key invalid or no longer valid
Error Message: Iframe dialogs must be called with a session key
While calling the stream.publish method as iframe
<script type="text/javascript">
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/fr_FR/all.js';
document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function()
{
FB.init({ appId: '303380259758621',
status: true,
channelUrl: 'http://www.crabegame.com/channel.php',
cookie: true,
xfbml: true,
oauth: true});
}
function PublishStream(score)
{
FB.ui(
{
method: 'stream.publish',
display : 'iframe',
message : '',
attachment:
{
name: 'CrabeGame',
caption: 'Essaye de battre mon score sur le Crabe Game !',
description: "J'ai réalisé un score de " + score + "points au Crabe Game !",
href: 'http://www.crabegame.com',
media:
[
{
type: 'image',
src: 'http://crabegame.com/media/crabe_fb.png',
href: 'http://www.crabegame.com'
}
]
},
action_links:
[
{
text: 'Play Crabe Game',
href: 'http://www.crabe-game.com'
}
],
user_message_prompt: 'Publier sur votre mur'
},
function (response)
{
if (response && response.post_id)
{
}
}
);
}
</script>

This means that you have no current user. Try this in order to call PublishStream:
FB.login(function(response) {
if (response.authResponse) {
PublishStream();
} else {
console.log('Not logged in');
}
});

you don´t need a logged in user, just remove display: "iframe", worked for me. it will still show in an iframe, but without error. don´t ask me why, with 1:1 the same app settings it works WITH the display value in another app of mine...at least that worked for me with the apprequest dialog, might be the same here.
and i would use "feed" instead of "stream.publish".
see here: https://developers.facebook.com/docs/reference/dialogs/feed/
also: Using Like Button and FB.ui (apprequests) On the Same Page Conflicts

Related

Facebook wall post response is blank screen in webview stuck in XD_proxy.php

I'm trying to post on facebook wall from Webview, its showing popup
to share content but after cancel or post it doesn't get back to
home share screen or unable to dispose popup window. The same
implementation is working fine in Browser, but not working in
Webview.
After sharing or cancel it should get back to share screen, but it
doesn't get back to the share screen and stuck in XD_proxy.php auth
link of facebook
Here's my code.
window.fbAsyncInit = function() {
FB.init({appId: "App_id", status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement("script"); e.async = true;
e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js";
document.getElementById("fb-root").appendChild(e);
}());
function streamPublish() {
FB.ui(
{
method: 'stream-publish',
display: 'iframe',
message: 'getting educated about Facebook Connect',
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'http://www.fbrell.com/',
picture: 'http://www.fbrell.com/f8.jpg',
actions: [
{ name: 'fbrell', link: 'http://www.fbrell.com/' }
],
user_message_prompt: 'Share your thoughts about RELL'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}

Adding a post-purchasing share following an order

I'm attempting to add a 'Share your order with your friends' option to our retail based website, and am following the faq based here: https://www.facebook.com/help/?faq=201527026558981
I have managed to manipulate the code as I think is correct, however in the FAQ answers the setup on the App is vague at best.
When testing in dev (on localhost) I'm receiving the following error:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
In the basic settings of the app I have no idea what settings need entering around the auth domain, site url, canvas url etc - I'm new to the facebook dev side of things. As far as I can tell I shouldnt need a site URL, as am not using facebook login. Does the canvas URL need to be populated, and if so, does that mean I then need to create a new page for the content of this app?
The code I'm running is:
<script>
window.fbAsyncInit = function() {
FB.init({appId: '1111111111111', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script>
function stream_publish(publish_text) {
var publish = {
method: 'stream.publish',
message: publish_text,
attachment: {
name: 'xxxxxxxx',
description: (
'xxxxxxxxx' ),
href: 'http://www.mydomain.com',
media: [
{
type: 'image',
href: 'http://www.mydomain.com',
src: 'http://www.mdomain.com/image',
}
]
},
action_links: [
{ text: 'Buy Now', href: 'http://www.mydomain.com', }
],
user_prompt_message: 'Tell your friends'
};
FB.ui(publish);
}
</script>
Can anyone advise how this should be done and what I'm missing?
Many thanks
Piers
From the error message, you don't have mydomain.com setup in your app settings.

FB.login Error in Internet Explorer

I am using connect-js (FB.login) to login users to share my page, in standard way. In all normal browsers (chrome, firefox, opera) it pops up a window with permissions request (everything is fine). But in Internet Explorer (7 and 8, didn't test in 6) it pops up window that says: "An error occurred with [myapp]. Please try again later."
This is my code:
<div id="fb-root"></div>
<script language="javascript">
var nombre = "";
var pic_big = "";
FB.init({
appId : '161599150607341', // App ID
channelUrl : '//emocionesverde.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
function conectarse() {
FB.login(handleSessionResponse, {
scope: 'publish_stream, user_about_me'
});
}
function handleSessionResponse(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
//console.log(response.name);
window.nombre = response.name;
getUserPic(response.id);
});
}
}
function getUserPic(uid) {
FB.api('/me?fields=picture&type=large', function(response) {
//console.log(response.picture);
window.pic_big = response.picture;
publicar();
});
}
function publicar() {
FB.ui({
method: 'stream.publish',
message: '',
attachment: {
name: 'Emoción es Verde',
caption: window.nombre + ' midió el impacto de sus acciones verdes. Te invitamos a conocer acciones para mantener el planeta verde con Emoción es Verde',
media: [{
type: 'flash',
swfsrc: 'http://mainteractivetools.com/erik/mifb/emocionesverde/Prueba.swf?pic=' + window.pic_big + '&nombre=' + window.nombre,
imgsrc: 'http://mainteractivetools.com/erik/mifb/emocionesverde/telefonica1.jpg',
expanded_width: '450',
expanded_height: '258'
}],
href: 'http://www.emocionesverde.com'
},
action_links: [{
text: 'Emoción es Verde',
href: 'http://www.emocionesverde.com'
}],
user_message_prompt: 'Escribe un comentario'
}, function (response) {});
}
$('#swfmapsdiv').css('visibility', 'hidden');
</script>
Have you tried adding p3p headers? It's an IE thing and clears up a lot of problems. However cryptic the codes are. What Facebook is essentially trying to do is share cookies across domains, which is a security flag. You need to say it's ok.
The issue could be in channelUrl, try to have the whole path there i.e http://emocionesverde.com/channel.html
Also login into facebook as app developer - the error message will be more detailed

Facebook Connect does not process jQuery ajax call after successful login

I've got the following script:
<script>
window.fbAsyncInit = function () {
FB.init({ appId: '<%: Facebook.FacebookApplication.Current.AppId %>',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
function FBLogin() {
FB.login(function (response) {
if (response.authResponse) {
ConnectFacebookUser(response.authResponse.accessToken);
} else {
alert('User cancelled login or did not fully authorize.');
}
}, { scope: 'email' });
}
$('#fb-button').live('click', function (e) {
FBLogin();
e.preventDefault();
});
function ConnectFacebookUser(at) {
var postdata = "at=" + at;
alert('This is the access token : ' + at);
$.ajax({
type: "POST",
dataType: "json", // what data type to expect from the server
url: "/FBConnect.ashx",
data: postdata,
success: function (data) {
// do nothing
alert('all good');
},
error: function (xhr, status, error) {
alert('error occured in FBConnect.ashx');
}
});
alert('finished');
}
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>
And for the html fragment:
Login with facebook
<div id="fb-root"></div>
When the link is clicked, a popup window for facebook shows up and when i enter my login details, i only see an alert to say "This is the access token..." but the rest of the code don't get processed. If I click the "login with facebook" link one more time, then everything gets processed as normal.
What could be the problem?
It works for me. I get the message 'this is the acccess code' and then i get a 'finished' alert. Check your Chrome debugger tools to look for any script errors that may be occuring silently.
Check out https://github.com/xocialhost/jquery.xocialCore.js/blob/master/jquery.xocialCore.js to see a jQuery specific way of doing this. One thing I noticed is that the jQuery click function when calling the FB.login was triggering the popup blocker in a few browsers I was testing with. I set this up to work around that issue but it's also a way to add a callback that is run properly during the init sequence.

Using FB.ui to post to Page wall

I'm using FB.ui to post to a Facebook user wall. However, I am uncertain on which parameters to use to post to a Page or Application wall. Any links?
I am trying to post to the Page wall as that page, not as the user's account.
Code to post to user account:
FB.ui(
{
method: 'feed',
name: name,
link: link,
picture: picture,
caption: caption,
description: redemption,
message: message
},
function (response) {
if (response && response.post_id) {
alert(response.post_id);
} else {
}
}
);
Got it:
you have to set the to and from values:
FB.ui( {
method: 'feed',
name: name,
link: link,
picture: picture,
caption: caption,
description: redemption,
message: message,
to: page_id,
from: page_id
},
function (response) {
if (response && response.post_id) {
alert(response.post_id);
} else {
}
}
);
I used the JavaScript SDK to post on user's wall:
function graphStreamPublish(){
var body = document.getElementById("txtTextToPublish").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
When I go through the Graph API Page I think if you change '/me/feed/' to 'pageId/feed' then it may post the message in that page. I am not sure. - just a suggestion.
To share on a friend's wall, as of February 2012:
FB.ui({
method: 'stream.publish',
app_id: appId,
display: 'iframe',
name: name,
link: link,
picture: picture,
caption: caption,
description: description,
target_id: friendIds
});
To post to facebook wall use the following.. .
Call the below js function using simple call as in below
Post to Wall image/text?
//facebook: post to wall
function publishWallPost() {
FB.ui({
method: 'feed',
name: 'Your App Name',
caption: 'Caption Text',
description: 'Your description text',
link: 'https://www.facebook.com/link/link.link',
picture: fbImg
},
function (response) {
console.log('publishStory response: ', response);
});
return false;
}
window.fbAsyncInit = function () {
FB.init({
appId: 'Your App ID',
status: true,
cookie: true,
xfbml: true
});
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
Sorry, this is an old question, but I thought this might be helpful for people who find it via google.
http://fbmhell.com/2011/07/facebook-share-popup-iframe-tabs-jquery/
Just remember target_id needs to be parsed into an int. The response["to"] comes back as a string.