Post Automatically Using Open Graph - facebook

I just created an app on Facebook (Open Graph). I want to publish a feed on the user's wall if they read that page. I can get it to execute in Unix Terminal but its not working via PHP or HTML. It should function like the Washington Post Social Reader where whenever you read a story, it shows up on your wall..saying "XYZ read a story on WashingtonPost"..I've got all setup done except for the last part.
I need to use a function in my website that will fire when the page loads..sending a post request to Facebook and publish the feed to the reading user (Provided they have authenticated my app).
I tried using the following method provided by Facebook but it didn't work
<script type="text/javascript">
function postCook()
{
FB.api('/me/YOUR_NAMESPACE:cook' +
'?recipe=http://example.com/cookie.html','post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
</script>
Please help ASAP

Log the error and see what Facebook tells you:
console.log('Error occured => ' + response.error.message);
Also use the Facebook debug tool to check your meta tags.

Related

Share video on facebook with custom message using jssdk version 2.0

I am trying to post photo/video on facebook wall using me/photos and me/videos/ method, which requires publish_actions ,user_photos and user_videos extended permissions. I submitted my app for Facebook review for approving extended permissions. I got reply saying that "People must enter all content in the user message field. Your app can't auto-populate the message field with any content, including links and hashtags, even if you allow users to edit the content before sharing."
As per the review feedback I have to allow user to edit the p refilled messages, The method I am using not showing share pop up to edit. Please guide me how to open facebook share pop up to edit the content.. Thanks in advance !!
FB.api('/me/photos?access_token='+accessToken, 'post', { url: fileUrl, 'message':description,access_token: accessToken }, function(response) {
if (!response || response.error) {
console.log("error occured");
// alert('Error occured: ' + JSON.stringify(response.error));
} else {
alert("Successfully posted on facebook");
// $("#status").html("Successfully posted on facebook");
}
});

FB.api 'post' returns error

The following code to write to a friend's wall from an app is returning an error. How can I debug this? The user ID (VALID_USER_ID) used below is valid - I read it from a separate function. The same problem happens when I do FB.api('/me/feed', 'post'...). What am I doing wrong?
function postToFeed()
{
FB.api('/VALID_USER_ID/feed', 'post',
{
message: 'Testing the Facebook JavaScript API',
link: 'http://developers.facebook.com'
},
function(response)
{
if (!response || response.error)
{
console.log('Error occured');
}
else
{
console.log('Post ID: ' + response.id);
console.dir(response);
}
});
You cannot post to a friend's wall, if you logged the error response you would see that.
Facebook has disabled posting to a friend's wall
Post to friends wall via the API generate a high levels of negative user feedback, including “Hides” and “Mark as Spam" and so we are removing it from the API. If you want to allow people to post to their friend’s timeline from your app, you can invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag).
https://developers.facebook.com/blog/post/2012/10/10/growing-quality-apps-with-open-graph/

Posting remotely to a Facebook page but post owner showing as from page

I am wondering if it is possible to post through a Facebook app to an associated page as if the post was done on the page itself. I.e. if I am logged onto Facebook and I go to a page I am admin for, then when I post it will appear with the name of the page rather than my Facebook name. I would like to replicate this behaviour but coming from an external website connecting through a Facebook app. I have made all of the connections and I am able to post ok but it is coming through as my name. I am using the Javascript API with the following to login:
FB.login(function(response) {//do some login processing},
{scope: 'publish_stream'});
Then I publish the message with the following after logging in and accepting the permissions:
FB.api('/[PAGE NAME]/feed', 'post', { message: Text to post }, function(response) {
if (!response || response.error) {
alert('Error occurred '+response.error.message);
} else {
alert('Post ID: ' + response.id);
}
});
My Facebook App has the Site URL and App Domain set correctly and I have setup the App as a Page Tab and combined that to my page.
So if anyone can let me know if it is possible and how to do it, it would be greatly appreciated
Thanks
It's all about Authentication, you have a User Access Token but you need a Page Access Token to authenticate as a page.
Here is the doc: https://developers.facebook.com/docs/authentication/pages/

Facebook Opengraph action publishing error

I'm trying to create a read button for my application. I have implemented the code as per the tutorial, but when i click publish button it says Error Occurred
<script type="text/javascript">
function postArticle()
{
FB.api(
'/me/svolzesocial:news.reads?article=<?php the_permalink() ?>',
'post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Successful! Action ID: ' + response.id);
}
});
}
</script>
I also tried debugging, but its showing no error there.
I have created publish button on this page Svolze post Please help me out to sort this problem!
You're posting to the wrong URL.
If you're using the build in read action you should post to
/me/news.reads
If you're using a custom action you should post to
/me/yournamespace:youractionname
At the moment, you're convoluting the two.
Nikhil,
Please also console.log(response) when there is an error to help debug. My guess is that you don't have the correct permissions - you will need publish_actions to publish on the user's behalf. Add a login button with the correct scope and then try to publish.
Some resources:
Perms page
Graph API Explorer

Posting on on a users wall on behalf of the user

I'm trying to figure out if the following is possible with the Graph API:
Post a message on the wall of a user (who has permissions publish_stream and offline_access set) on behalf of that user, so the poster doesn't depend on the current session.
This seemed to be possible with the old rest api (stream.publish). This function has some known bugs though and seems te be deprecated.
With the new api it's possible to publish on a users wall but it doesn't take the poster as an argument (as did stream.publish). See here.
Is this because Facebook doesn't allow such third party publishing anymore, or am I missing something here?
Any help would be greatly appreciated,
from here http://developers.facebook.com/docs/reference/javascript/FB.api
If you have an authenticated user with
the publish_stream permission, and
want to publish a new story to their
feed:
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
it is the javascript version but i am pretty sure there is an equivalent one for php