Very confused, but my open graph works. The only problem is I have to hit refresh a few times for it to actually post to timeline.
What could be the problem here?
You should add the javascript timeout function to call facebook a few seconds after the page has loaded. E.g.
setTimeout( function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// publish action to facebook
FB.api( '/me/news.reads', 'post', { article : 'http://www.yourdomain.com/your_article/' } );
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
}, 2000 );
This will allow enough time for Facebook SDK to load and initialise, before posting your action off to facebook.
Related
Goal : Connecting an application with existing Facebook page.
Why ? I want to allow user to use their page as bot. Facebook app is a bot.
Reason : User wants a bot for Facebook page but does not allow admin permissions.
What I've tried :
Get all users pages :
if ( typeof (response.authResponse) !== 'undefined')
{
token = response.authResponse.accessToken;
$.ajax({
url: "api/FB/GetCode?token=" + token,
}).done(function (data) {
var mySelect = $('.dropdown');
mySelect.empty();
$.each(data.accounts.data, function (val, text) {
mySelect.append(
$('<option></option>').val(text.access_token).html(text.name)
);
});
mySelect.show();
$('.connectWithBot').show();
});
} else {
//do the login logic
}
Then when user has chosen page :
FB.api(
'pageId/subscribed_apps?access_token=' +
$('.dropdown').find(":selected").val(),
'post',
function (response) {
console.log(response);
if (response && !response.error) {
console.log(response);
}
});
So when one page instance is connected with one application, this not gonna work anymore. Its okey that way.
Is it possible to get this work ? Or maybe you guys have a better idea ?
I’m creating a custom share to facebook functionality, which has been more complicated than I originally thought.
I’ve had to create a facebook app and then use It’s ID to get it going.
If you try to share the page on facebook, it gets you login to facebook(if not logged in), then it requests access to your profile(only on your first share), and then proceeds to share dialogue to let you share it.
However I’ve noticed that other sites including youtube and BBC, that they don’t request access to share on facebook, It will take you straight to the share dialogue instead.
Is there a way to achieve this?
Code using is below:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '*APP_ID*', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
link : '*LINK*'
});
$('.share-print .facebook > a').click(function(e){
e.preventDefault();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
facebookSend();
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
FB.login(function(response) {
if (response.authResponse) {
console.log('Logged in');
facebookSend();
} else {
console.log('Not logged in');
}
});
} else {
// the user isn't logged in to Facebook.
FB.login(function(response) {
if (response.authResponse) {
console.log('Logged in');
facebookSend();
} else {
console.log('Not logged in');
}
});
}
});
});
var facebookSend = function() {
console.log('facebookSend started');
FB.ui({
method: 'feed',
display: 'iframe',
link: '*PAGE_LINK*'
});
}
</script>
i use the wordpress social login plugin to log in on my page. it works also to log in with a fb-page but if i want to share (as user it works fine) it does not work
i load the SDK Asynchronously and use JS SDK to post like:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me/feed', 'post', {
link: MYLINK
}, function(response) {
if (!response || response.error) {
jQuery('#warning').html(errorwarning);
}
else {
alert('response.id')
}
else
...
...
...
I get the id of the post as respone, but there is no post on the FB-pages wall
Loged in as user it works.
I added these permissions: publish_stream, manage_pages and offline_access.
you must use your page ID instead of me
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/'+page_id+'/feed', 'post', {
link: MYLINK
}, function(response) {
if (!response || response.error) {
jQuery('#warning').html(errorwarning);
}
else {
alert('response.id')
}
else
...
...
...
your answer will only let the user post to the FB page as 'user' not as 'page'.
I think the question is "How to post as PAGE"
I am trying to use Facebook javascript library function : FB.getLoginStatus.
This function works when the user is logged but fails when user is not logged to facebook.
Here is my code:
FB.getLoginStatus(function (response) {
console.log('entering the function!');
if (response.status === 'connected') {
FB.api('/me', function (response) {
if (response.name != undefined) {
console.log("Welcome, " + response.name);
}
});
} else if (response.status === 'not_authorized') {
console.log('not logged to app');
} else {
// NEVER POPUP
console.log('user not logged');
}
});
The last event (user not logged never popup), when a user is not logged, the function is not event firing and I do not see the log [entering the function].
Do someone has an idea to detect if a facebook user is connected.
Regards,
Linvi
I sent a bug report for this issue and Facebook developer reported that it was actually a current known issue.
I'm working on a Facebook app that uses Facebook groups, and I'd like to open up a Feed dialog to let the user post a notice to the group's feed. I have a user who is in the group and I've got the relevant permissions as well.
I've tried passing the group's Facebook id in the https://developers.facebook.com/docs/reference/dialogs/feed/ feed dialog, but get a Facebook error. There doesn't appear to be a programmatic way to do it either: the group's feed (described at https://developers.facebook.com/docs/reference/api/group/) isn't documented to accept POSTs either. Is there a way to post a message to the group using the Graph API or one of the other API methods?
I just made a test and it's working as any other wall.
I made a POST to 'GROUP_ID/feed' with a message variable with a value and it worked. I logged into the app as the group owner.
Using facebook php-sdk:
$facebook->api('GROUP_ID/feed', 'POST', array(
'message' => 'Testing...'
)));
I would suggest to use javascript instead as it wont cause post back of our website.
Check out my application to see if that what you want -> WooTube
function Promote() {
var lnk =
'http://www.wootube.woolei.com?v=<?php echo $_GET["id"] ?>';
FB.login(function(response) {
if (response.authResponse) {
//Post To WooTube Group
FB.api('/271691796276524/feed', 'post', {
message: lnk,
link: lnk,
},
function(response) {
if (!response || response.error) {
//alert('You have to join the group first!');
} else {
//alert("Successfully Posted to WooTube Group!");
}
});
//Post to Wootube Page
FB.api('/173724382762792/feed', 'post', {
message: lnk,
link: lnk
},
function(response) {
if (!response || response.error) {
//alert('You have to like http://www.facebook.com/WooTubes first!');
} else {
//alert("Successfully Posted to WooTube Page!");
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'publish_stream'
});
}