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

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?

Related

Google Apps Script - "authorization required" occurring in every Document created from template

I have a Google Document that has a custom UI menu with an option to add a new page to the Doc and populate it with some data. I use this Doc as template for creating numerous other Docs for a single user via webapp.
So my user comes to my webapp, clicks to generate this Document, the document is created from the aforementioned template Doc (containing the bound script to allow the user to add more pages with additional data). The user clicks in the custom menu to create a new page, and before that chunk of code is executed, he gets the 'Authorization Required' screen. I've already prepared him for this so he know how to proceed - no big deal. he goes on to use the Document for his tasks and closes it when he's finished.
He now needs to generate a new Document from the same template and add additional pages just as before. Once again, he gets the 'Authorization Required' screen. Now he's thinking 'I just authorized this... what's gong on?' and is now confused.
Since these Docs are generated on the fly from within the webapp, I have no way to go in and authorize anything but the script in the template before the user gets to it. But is there really no way to authorize that script in the template doc and have it carry over to all the new docs created from it?
Instead of including the code as a bounded project publish it as an add-on. This way the user only will have to authorize the code once.
Related
How to avoid re-authorization request for a copied Google Spreadsheet + script

How can I use FB.ui to post a user story?

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.

Facebook Graph API: Explain permissions to user?

Is it possible to ask for the wanted permissions and displaying some individual text in the permissions-dialogue that's showed to the user? E.g. "We use the permission to read your mail address to create a new account in our community."?
Thanks,
indect
Earlier the Login Dialog would have the option to display the app description that developers could use to inform the Users about the need for the specific permissions. Which looked like following and was described in this blog post
But the Login Dialog has then seen few modifications, as outlined by this blog post for grater clarity and control due to which the Login Dialog has changed to its current form which has no option for the developers to inform Users about the request. If you want to inform about it, do it prior to sending the User to authorization, as the new Login Dialog looks like
No, these messages are default by the facebook.

Publishing Actions: link back to website from user wall

I am building a website that will require the user to provide permission for us to post a story back to the users wall when the user takes an action on my website. I would like the story to include a link back to my website so that friends can see the actions taken.
I am not sure of the correct permissions because I cannot get a link back to my website from the story post. I saw publish_stream, but that appears to be old now. Any pointers to FB policy and documentation would be appreciated. I
Instead of making stream posts, you should instead use Open Graph actions, which will give you a much better result and feel less 'spammy' to your users. I can't post code that will do this for you as it would need to fit into your existing setup, however it is a relatively simple process, which is well documented (https://developers.facebook.com/docs/opengraph/actions/):
Auth users by prompting them to give publish_actions permission and any other permissions your app might need.
Store the users access token in your database (not necessary if you're using the client-side Javascript SDK, but you might want to do it anyway)
Setup your Open Graph Actions and Objects in the Developer Dashboard.
When a user performs a relevant action in your app, make a simple Graph API call to the following endpoint:
https://graph.facebook.com/me/YOUR_APP_NAMESPACE:YOUR_ACTION? YOUR_OBJECT_TYPE=YOUR_OBJECT_URL&access_token=YOUR_ACCESS_TOKEN
Done.
You can add extra elements to the action, such as action links, however the basics are outlined above. Once you've performed those steps, the user will see something like this on their Timeline:
The part that says 'on NYCCookbook' is customisable and clicking on most parts of this story will bring Facebook users back to your site. There are many benefits you can get if you implement this all correctly.

Django and Post to Facebook (no authentication)

OK, I need some help understanding the process behind Facebook's website integration process and how I can integrate it into my web app....
In its most basic form, my site stores and displays users' comments about products (there's more to it than that, but that's all that's relevant for this question). What I'd like to do is allow them to post that comment, together with the name of the product (and my site), to their Facebook wall by clicking a button.
I do not need the users to log in to my site at all, either with Facebook or any other authentication system and the Post to Facebook part is optional.
Obviously if they decide they do want to post their comment to Facebook, then they'll need to login, but I'd rather temporarily take them away from the page to login, post and then be brought back to my site.
What I need to know is how much of Facebook's APIs, Open Graph and Auth systems do I actually need to integrate?
I had hoped that I might be able to generate a simple link to Facebook with their comment embedded as a POST element...?
I'd be really grateful if someone could point me in the right direction!!
(P.S. I need a similar solution for Twitter, but I think that's easier!?!)
The Feed Dialog doesn’t allow including of a pre-set message any more, so you’d have to make that post via the Graph API if you want to pre-fill the message (and even then, you should only do so, if you’ve given the user the possibility to edit the pre-filled message first).
See here for how to make a post on a user’s behalf via Graph API, https://developers.facebook.com/docs/reference/api/user/#posts
You can do that all client-side, if you embed the JavaScript SDK into your page.
You need to set up an app on FB, then have the user connect to it (using FB.login), ask for the necessary permission (publish_stream) while doing so, and after successful login use FB.api to make the Graph API call.