How can I use FB.ui to post a user story? - facebook-graph-api

Currently, the below FB.api function is invoked on a click event and posts a user story on the user's timeline (the FB app is in sandbox mode right now and the user story is still pending review):
FB.api( // creating the user story
'/userid/mynamespace:myaction',
'post',
{
myobject: fbObjectId, // retrieved in an earlier FB.api call
access_token: accessToken, // retrieved in an earlier FB.getLoginStatus call
message: customTextFromUser, // prefilled by my app (FB doesn't approve of this)
image: ImageURL, // prefilled by my app (FB is OK with this I think)
'fb:explicitly_shared': true // requires that I take the user out of the normal flow of the app which is why I want to show a modal first
},
function(response) {
// handle the response
console.log(response);
if (response.id) {
alert("Success! The user story has been shared on Facebook!");
} else {
alert("Woops! Something went wrong sharing the user story on Facebook. Please try again.");
}
}
);
What I think I need to do is show a modal dialog box such as in the case of when FB.ui is invoked to give the user an opportunity to add a User Message and then post the user story along with the User Message (if any).
Will I need to create my own custom modal dialog box or can I use FB.ui in some way to achieve this?
Note: The above API call works fine in my tests. Granted, variables such as mynamespace, myobject, and myaction have been obscured in the above code sample.
My real problem is the user story is just not being approved by Facebook because I supposedly need to "take the user out of the normal flow of the app" in order to Explicitly Share the user story with an additional optional User Message. I guess I need a strategy to address this issue rather than a specific code sample answer.
Here is the latest feedback I got from Facebook:
Your action doesn’t follow section IV.2 of the Platform Policies:
https://developers.facebook.com/policy/.
Words in the user message field must be manually written by the user
and can’t be pre-filled by the app, even if the user can edit or
delete the words. Learn more about user messages:
https://developers.facebook.com/docs/submission-process/opengraph/guidelines/action-properties/#usermessages.
Posting explicitly shared content needs to be optional for users. A
sharing control needs to be in-line whenever a user shares something
and it can’t be in a separate settings area. The content should have a
user-generated component or the user needs to be taken out of the
natural flow of the app in order to decide to publish the story back
to Facebook. Your current action integration shouldn’t be labeled as
“explicitly shared.” Learn more about explicitly shared content:
https://developers.facebook.com/docs/submission-process/opengraph/guidelines/action-properties/#explicitlyshared.

If you use a test user created for your App, or use your developer account, you should be able to see the story published before it's approved.
The API call you're making also needs to be updated slightly. Instead of using User ID in the FB.api, just use /me/mynamespace:myaction. The access_token also doesn't need to be included, as it's automatically passed by the call providing the user is logged in.
Finally, is your object actually called myobject? The name must match the settings you entered for your story, e.g. 'article` or another valid type.
To help debug the issue, try a simple API call first (e.g. remove message and image) and see what happens. Then add the other parameters back one by one to see which one is causing the issue.
Edit
To get the action approved, you need to make sure the user is entering a custom message in one form or another - usually via text input on the page. If you are sharing pre-defined text the user hasn't entered, facebook won't approve it.
If you want to share a pre-written message, it might be better to share it in another way, like a caption in the story itself.

Related

Sharing via API on Facebook - differentiate between "success" and "canceled"?

The documentation for Facebook's Feed Dialog and Share Dialog suggest that if a user is not logged in to your app, you have no way of determining whether or not the user actually shared the story or just opened the dialog and clicked "Cancel".
My experimentation seems to match this behavior. Can someone please confirm that this is the case? (I would love it if I were wrong)
To clarify: I understand there's no way to receive post_id as a response if the user is not logged in (Facebook has deprecated this behavior). However, I'm surprised there's not even a way to determine if a post was actually shared or if the "Cancel" button was clicked...
It seems like exposing this isn't a "privacy risk" for Facebook; having this success/canceled boolean available would be very useful in building a good UX.

How to create a facebook event on users behalf using javascript sdk

I'm trying to piece together information and different chunks of code scattered throughout the documentation on how to make this happen, since there aren't good examples.
I know I have to first get the create_event extended permission which I get with this code:
FB.login(function(response) {
// handle the response
}, {scope: 'create_event'})
;
I know that I also have to issue a HTTP POST request to 'PROFILE_ID/events' with the create_event permissions and the necessary parameters.
My problems are: 1. I don't know how to collect the create_event permission once it is given. If I run the code above, a dialog box will open asking for the permission but once I accept, only a blank page follows.
2. If everything works the way it supposed to with the permissions request and the post request, will my app see a create event page like I would if I were to create an event on my own from my profile? What interface gets seen from the app? Can I take a user from my app directly to the facebook create event page?
I don't know how to collect the create_event permission once it is given. If I run the code above, a dialog box will open asking for the permission but once I accept, only a blank page follows.
That’s how it works. Everything you want to show to the user after successful login, you have to implement yourself.
If everything works the way it supposed to with the permissions request and the post request, will my app see a create event page like I would if I were to create an event on my own from my profile? What interface gets seen from the app?
No “interface” at all – it’s up to you to build that.
Can I take a user from my app directly to the facebook create event page?
The user can go their by themselves. Why would the need your app for that?

What's supposed to happen when you set up a realtime subscription to "likes"

I'd like to be notified when my site's users "like" something. This is supposed to be possible according to https://developers.facebook.com/docs/reference/api/realtime/, and I've in fact been able to set up my app so that it's subscribed to "likes".
The question is, now what happens? If my user clicks on a "like" button, my app does get an update at the usual callback. The problem is that it's a "feed" update to the user object, which just means that the user's feed has changed in some way, and it's up to you to figure out how. I guess I was expecting that I'd get a "like" update to the user object, but that's not what I'm getting. Any insights out there?

Facebook graph, post action with extra parameters

I have created an application with their associated Open Graph actions. Got problem with submitting one action, which is using extra field "message". When admin or tester using this action it works fine, but it is not working with facebook's test users, such is "Auth Dialog Preview User", it gives an error "Message: This action is not allowed to set a user message because this property was not requested for approval." Why it gives this error to the test user? And when i submit this action, facebook replies me that they can not test this action... What i missed?
http://gyazo.com/42ebb0a5c12f3c47fed64f5eb9930f61
Why it gives this error to the test user?
Doesn’t it quiet clearly say so:
"Message: This action is not allowed to set a user message because this property was not requested for approval."
…?
Users that are not admins can’t post actions that have not been approved by Facebook.
I've been beating my head against the wall on this problem as well.
First: There is a Facebook Bug that is currently triaged on this topic.
Facebook Bug Link
Second: I noticed Facebook has updated the description of the Message property.
message: Allows users to write a personalized message attached to this
action. You can only use user message when the text is entered by the
user (not pre-populated). string
Facebook page that details the Message parameter
You'll notice it clearly states that it can't be pre-populated now. I don't remember it saying that previously (Of course my memory could be failing me) and I'm curious if that means even if the user composed the message on my application, Facebook considers the string I'm feeding the action pre-populated even though it's an actual unique comment written by the user. In other words you may have to use Facebook code (plugin, dialog, etc...) to prompt the user to actually enter a message attached to the action.
Third: FYI, I was able to get my action approved (With the Message parameter) but the same error persists for all users attempting to submit the action with the exception of admins and testers, so getting your action approved won't likely alleviate the issue. It's either an actual bug or a misunderstanding of the capabilities/functionality of the Message parameter.
Apologies for this being a partial answer slash extension to the question.

Action approved - publish_actions still not working

This question has been asked many times before, but they all seem to relate to problems before the Open Graph was 'opened'. As a new user, I also can't make this question useful, i.e no images or links. If you want to see the images I've posted, you'll have to copy and paste.
First of all, my Action is approved.
http://i.stack.imgur.com/hAFHr.png
Additionally, the action shows as being available to all users.
http://i.stack.imgur.com/IrrWW.png
publish_actions has been added to the Auth.
http://i.stack.imgur.com/PdJiA.png
I also have objects and aggregations setup correctly.
The auth preview also shows the correct settings (although the dialog currently doesn't stay open to see it, it used to).
When I try and connect with FB to the site, I don't see publish_actions. Instead I see the second stage of the dialog, for publish_stream. I set this by mistake the first time I saved the app, but quickly changed it.
http://i.stack.imgur.com/n819f.png
http://i.stack.imgur.com/gkXfg.png
This is where I think it gets even stranger. If I take a look at the FB profile for one of the app developers, and click through too the app from there, while not registered, I see the correct permissions.
http://i.stack.imgur.com/SsOVI.png
Yet another twist to the tale, which makes it even harder for me to debug, is that it seems since playing with the aggregations, I can't even get publish_actions permissions despite being listed as an app admin. (I've read that every action needs an aggregation before FB will process any actions sent by the server.)
/**/ FB.ApiServer._callbacks.ff2f1615c({"error":{"message":"(#200) Requires extended permission: publish_actions or App must be on whitelist","type":"OAuthException","code":200}});
That's the error I get when I complete the action on the site, http://purple.fr/boutique
Have I missed a setting somewhere? Have I done something I shouldn't? Should any of this be controlled in the code on the site?
When a user connects to your site, you should be asking for the publish_actions permission instead of the publish_stream permission. The referral dialog settings (where you already ask for publish_actions) only works when a user clicks on the action from within Facebook. It won't work for users already on your website.
In your login function (FB.login), make sure you add the permission publish_actions.
That aside, it looks like it's all working now.
http://i.stack.imgur.com/jAosv.png
http://i.stack.imgur.com/Wbgf5.png