Share video on facebook with custom message using jssdk version 2.0 - facebook

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

Related

Initiate login for custom stories

I have created a custom story to be posted on facebook timeline when user clicks on a share button.
While i was logged into facebook, I could successfully post on timeline using the following code
function postLike() {
FB.api(
'https://graph.facebook.com/me/og_pricepan:compared',
'post',
{ product: objectToLike,
privacy: { 'value': 'SELF'}
},
function (response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
Now, when the user is not logged into facebook, I get the following error:
Error: An active access token must be used to query information about the current user.
Shouldn't the login window get open by itself asking the user to login into facebook or I need to do something on my end to handle this situation?
Also, do i need to submit my application for review before users can create custom stories from my website to their timeline?
Shouldn't the login window get open by itself asking the user to login into facebook or I need to do something on my end to handle this situation?
No. You need to explicitly login the user by following the Facebook Login Flow to request an access token
Also, do i need to submit my application for review before users can create custom stories from my website to their timeline?
Yes and No. No, because it's not like you will have someone from Facebook Support Team going through your app to make sure your app ticks all the boxes. Yes, because you will need to register your app with Facebook. So, technically all you need to do is register with Facebook as a developer and register your app in order to get an app secret and API key. You can have your app in "Sandbox mode", create test users and test your integration with Facebook before you publish it live. There's few requirements you need to meet before publishing it, such as providing set of logos of a specific size, etc. Here's a blog explaining part of the process, but really, the process is very straight-forward and you should be able to get through easily by yourself.
Now, the error you are getting says it all. There's no user logged in to facebook. The endpoint you are trying to post to, requires a active valid access token, if it doesn't exist then there's no context, no user authenticated and you need to explicitly authenticate the user by invoking the login dialog...
FB.login(function(response) {
if (response.authResponse) {
// The person logged into your app
} else {
// The person cancelled the login dialog
}
});
If you need to know whether a user is logged in or not, you can follow to simple approaches:
1.By invoking the FB.getLoginStatus function
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
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
}
else {
// the user isn't logged in to Facebook.
}
});
2.Or, by subscribing to the auth.authResponseChange event when initializing the framework and setting the status option to true
There's a full-legged tutorial on Facebook Developers Site for Javascript SDK explaining both approaches.
Hope it makes sense

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/

Post Automatically Using Open Graph

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.

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