post as a FB-page does not work - facebook

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"

Related

Facebook send dialogue authentication

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>

Facebook API feed dialog - prevent unnecessary click

hi,
Using Facebook's API it's possible to prompt a user to post to his/her wall using the feed dialog. However, using the javascript SDK, this requires two clicks: one on the button which brings up the dialog, the other on the "Share" button within the dialog.
Is it possible to get rid of one of these clicks? I thought of two approaches:
Embedding the dialog within an iframe, as Facebook provides a URL for a full page dialog. That will require the user to click only on the "Share" button. Apparently Facebook blocks that option.
Using an access token and display=iframe, but I want to avoid the user having to authorize my application.
Any ideas?
i would suggest you to use fb.api instead.
function PostToMyWall(){
FB.login(function(response)
{
if (response.authResponse)
{
//Post to my wall
FB.api('/me/feed', 'post', {
message: lnk,link: lnk
},
function(response) {
if (!response || response.error) {
// //alert('Error occured');
} else {
// //alert("Successfully Posted to My Wall!");
}
});}else
{
alert('Not logged in');
}}, { scope : 'publish_stream' });
}
My application got a similar function, check it out at www.wootube.woolei.com - "Post to WooTube Page and Group"
or popup when the page using jquery
$(document).ready(function() { FB.ui({method: 'feed',
name: mdtxt,
link: lnk,
picture: hackImageUrl(img,fld),
caption: '<?php echo $clickme; ?>',
description: '<?php echo $app_desc; ?>'
},
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert("Successfully Posted to Group");
}
});});

facebook open graph have to reload page to post to timeline

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.

Check if Facebook JS-API app already has been given permission

I have a small script that unlocks some content on a page when a user logs in via Facebook and posts some information on their wall.
I want to avoid any duplicate posts (spam) in the event the user visits the page a second time and repeats the process.
Is there a way of (when asking for the permissions) to tell if they have already been given and therefore skip the sharing part of the script?
Here's my code:
$('.preview a').click(function(e) {
e.preventDefault();
FB.login(function(response) {
if (response.session) {
FB.api('/me/feed', 'post', {
message: 'Just unlocked the exclusive preview of...',
picture: 'http://website.com/share.png',
link: 'http://www.website.com',
name: 'Name goes here',
description: 'Description here'
},
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
$('.preview').hide();
$('.clip').show();
}
});
}
},
{perms:'read_stream,publish_stream'});
});
From 2011 to 2014 a lot of things change..
I made this solution to check for "user_friends" and "publish_actions" permissions, if not allowed the both, force the user to "re-autenticate". The callback method will only be called when all permissions are given.
function login(cb,forceAuth) {
FB.getLoginStatus(function (response) {
if (response.status !== 'connected' || forceAuth==true){
FB.login(function (response) {
checkPermissions(cb,false);
}, {scope: 'publish_actions,user_friends'});
} else {
checkPermissions(cb);
}
});
}
function checkPermissions(cb,forceAuth){
FB.api(
"/me/permissions",
function (response) {
if (response.data[0]['publish_actions']==undefined || response.data[0]['publish_actions']==0 ||
response.data[0]['user_friends']==undefined || response.data[0]['user_friends']==0) {
if (forceAuth!=false)
login(cb,true);
} else {
cb();
}
}
);
}
How to use:
login(function () {
myLogedAndAllowedFunction();
});
I've written a tutorial about this here, and here's an example:
FB.api({ method: 'fql.query', query: 'SELECT read_stream,offline_access,publish_stream FROM permissions WHERE uid=me()' }, function(resp) {
for(var key in resp[0]) {
if(resp[0][key] === "1")
console.log(key+' is granted')
else
console.log(key+' is not granted')
}
});
There's also a JS REST example there in the article just for reference.

Is there a way to post a message to a Facebook group's feed?

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'
});
}