How to create a custom poll on facebook via open graph? - facebook

I wanto to create on my facebook page (facebook.com/genericco) a custom poll, in it I wanna create funny polls people can vote on (mainly yes or no answers) and I'd like to post on the voter's wall the action (john doe voted yes on Genericco's poll: Do you think chicken-fish should stop smoking for health issues?).
So I could not do that just using graph API and reading my own questions...so I decided to use the open graph! I created an action called vote with the custom property answer as a boolean...
I've also created the object poll with image,question, title, description and the custom property question...
I've also populated with custom data in the aggregations part.
Then i used Putty program to run the code and be able to submit my custom action for approval...
My question now is...How do I use it? How do I put this together to achieve the objectives I've proposed on the top of this question?
can anyone shed a light?

So...I managed to build the customized poll app with Open Graph in facebook. its going well...but its not 100% yet. let me tell you guys why:
1 - So I managed to understand how to creat an action, I called it "Vote", it is connected with the Object type "Poll" I created; The action "Vote" has 2 custom properties: "Answer" wich is a String and "Name" wich is also a String;
2 - Then I created the object "Poll" and I filled it with sample data and stuff and also I created the custom property "Question";
3 - Then I created the aggregation "Enquete Ociosidade" (roughly translating would mean sloth poll) and the data is displays is the action "vote" and in the Caption I used something like this {poll.question}{name} thinks {answer};
Then to make it work I had to send a sample of the action to facebook somehow, I had no idea how to do this so I used Putty and simply pasted the code facebook provides for that; It worked;
Then comes the hard part, how would my front-end app send those info to facebook so I could register the action? Well I'm glad you asked!
I tryed till it worked...YOUR APP MUST HAVE PUBLISHING_ACTIONS PERMISSION THIS IS VERY IMPORTANT!
so...this is the code I got working:
FB.api('/me', function(response) {
//alert(response.name);
FB.api('/me/genericco:votar_poll&enquete=http://www.limonadaweb.com.br/genericco/poll_data.php&resposta='+resposta+'&nome='+response.name+'&access_token='+_token+'' ,'post', function(resp) {
if (!resp || resp.error) {
alert('Error occured '+resp.error.message);
//mostrar caixa de diálogo que algum erro ocorreu;
} else {
alert('Post was successful! Action ID: ' + resp.id);
//fazer algo legal para demonstrar que deu certo o voto;
}
})
});
what I did was...first I make a FB.api call to get the users name, in the callback I make a FB.api call to register the action VERY IMPORTANT TO PASS THE ACCESS_TOKEN TOO...and must be POST.... and that is all there is to it! very cool right? And all that code is inside a function my app calls whenever the user votes and sends a boolean value that I use as the answer to know if the user voted 'yes' or 'no'.
That is all very good and is working fine! Just fine....
My problem now is that now when the action is published in my timeline and newsfeed and stuff it sends the user to this link below...it has absolutely nothing visual in it...it is the poll's data...a bunch of metatags...
i'd like to know if it is possible to send the user to another link when he/she clicks the link of my feed...
http://www.limonadaweb.com.br/genericco/poll_data.php?fb_action_ids=10150744684398313&fb_action_types=genericco%3Avotar_poll&fb_source=other_multiline

Related

How to comment on embedded facebook post on a website without leaving it

I recently made a fanpage and i have used embedded code from one of the post of my fanpage to my website.
So now It shows the post on my website and number of likes but i would like to show current existing comments which that particular post had got. Right now it is just displays the comment button and if i will click that then it will take me to the fanpage just for the sake of comment.
So heres what i need
1 - Comment on the embedded post without leaving the website to facebook.
2 - Displaying all the current existed comments ..
the image right now look like this
Thats very simple. First, you need to login user and ask for publish_stream permission. After the user is logged in, you just to display a button that triggers the function named comment, passing the ID (corresponding to the object user is going to comment to) .
You will also need an input field for inserting the comment (of course), and using jquery .value we will get the value of the input field .
PS: Specify NAME and ID on the message input field. I dont remember wich one is, put both of them .
After getting the variables, we will call FB.api, specifing the variables id and comentario than get the response for handling the result (if you want), you can try to reload the comment plugin, or refreshing the page .
function comment(id) {
var id = id;
var comentario = document.getElementById("message").value;
FB.api("/"+id+"/comments","POST",
{
"message": comentario
},
function (response) {
if (response && !response.error) {
alert('Comentado !');
} else {
alert('Erro !');
}
});
$("#atividade").html('COMENTADO');
}
That is very simple and fun, but you will need to get authorization from facebook platform to ask users for publish_stream permissions before production .
I think David's answer will just post a new comment, not show all post's comments.
Unfortunately there is not a option to show the comments on embed posts.
You need to get the post id, call a api to load all comments and so embed each one of them. Yeah, that's terrible...
Open the graph api explorer:
https://developers.facebook.com/tools/explorer/
Type {post-id}/comments on GET input and send it to see a response example.
And that's how you embed comments:
https://developers.facebook.com/docs/plugins/embedded-comments
I don't think loading all comments from all posts will have a good performance. I suggest you to create a button "see comments" which call the api. After that you can create the input text for new comments, like David said.

Adding a Facebook comment on a URL and have it displayed on user profile

I am creating a web application that displays a list of images taken from Flickr and I would like a user to login through Facebook and allow them to comment on those images. I was able to get the login/authentication working but I am now having trouble to enable a user to add a comment (as oppose to a Facebook 'post') on a Flickr image and have this activity show up on the user's Facebook profile/feed (i.e "John Smith commented on a link").
Here is what I have so far:
var fbCommentApi = '/me/myappname_ns:comment?access_token=' + fbUserToken + '&method=post' + '&picture=[WEBSITE_URL]' + selectedItemId;
FB.api(
fbCommentApi,
'post',
{ message: txtObj.value },
function (response) {
if (!response || response.error) {
alert("Sorry, there was a problem. Please try again later. [API]");
}
else {
alert("Thank you. Your comment will appear shortly");
hideCommentBox(txtObj);
}
}
);
The above code doesn't create a comment but instead it creates a post on the user's timeline with the URL attached. So when I try to retrieve comments for the WEBSITE_URL item through Facebook Graph...
'https://graph.facebook.com/comments/?id=[WEBSITE_URL]' + itemID
...I end up with empty data being returned.
I have an Action Type called 'Comment' in my Facebook app and that's the action I am using when trying to add the comment.
Thanks in advance and I look forward to your answers.
UPDATE 1: It seems now that if I use Facebook Graph this way.. graph.facebook.com/me/appname_ns:discuss?access_token=[TOKEN]&website=[URL]&met‌​hod=post
..it would just add an entry to the user's Activity box in their timeline, I didn't even pass a comment or message parameter to the URL as a query string parameter. That could be part of the problem.
UPDATE 2: According to another StackOverflow question, there seems to be no way to get a view of all actions done by all users, it has to be done per user (an API call per user). Therefore another way of handling this particular issue is to save the comments (or whatever action performed) to our own database.
Well, an Open Graph action is not a comment, even if you name it comment …
If you want a real Facebook comment, then either get a reference to an object that actually can be commented upon; or substitute comment with post/link post.

Facebook Graph API does not return the event picture

Edit: Seems like Facebook finally fixed this bug!
Could you help me understand why this is happening:
This is a public event with a picture:
https://www.facebook.com/events/282054218538223
But when I try to access http://graph.facebook.com/282054218538223/picture, all I get is a default picture.
Here is another public event: http://www.facebook.com/events/266496120103339
But this time, accessing http://graph.facebook.com/266496120103339/picture returns the event photo.
What's the difference between the 2 events?
This answer doesn't explain why the request doesn't work using Graph API but might help someone who needs to to retrieve event profile images.
With FQL you can retrieve the event profile image like this:
SELECT pic, pic_small, pic_big FROM event WHERE eid=282054218538223
using the event id from Robin's first example. This call returns urls to the event profile image in 3 different sizes. It works for both examples in Robin's question, just change the event id.
Try it in Graph Explorer with Robin's example:
https://graph.facebook.com/fql?q=SELECT pic,pic_big,pic_small FROM event WHERE eid=282054218538223
and MoXplod's example:
https://graph.facebook.com/fql?q=SELECT pic,pic_big,pic_small FROM event WHERE eid=271148229633674
Make sure you have access token if needed as outlined in the FQL event table.
having the same problem. it appears to indeed be a bug with the Facebook Graph API.
I currently count at least three separate open bug-reports on the Facebook Developers Bugs page that describe and reproduce the problem (you may need to be logged into FB to access the information) :
Cannot retreive picture of newly created events via Graph API
Some event covers not available via Graph API
Event picture is not accessible via API
fwiw, it might be a good idea to subscribe to all three (duplicate) bug-reports.
I was fighting with this problem this evening. The docs are saying to use picture but what I found exploring fields is this one:
{event-id}/?fields=cover
which finally returns:
{
"cover": {
"offset_x": 99,
"offset_y": 50,
"source": "{url}",
"id": "{id}"
},
"id": "{id}"
}

I am having significant trouble getting items to post a read News items in the time line

I can't seem to get a post to work for our news items as FB News items. I was able to create a whole custom type and I discovered the News specific option after I had implemented a standard object:action setup successfully so conceptually this should work since we had all the pieces working before.
Originally we (GlobalPost) created out own app and Auth for our own name space gp_storyshare for our article object with a action read.
Then I ran over this
https://developers.facebook.com/docs/opengraph/news/
and sighed, since it wasn't linked to any of the other documentation and started over. Here is where I'm at.
Since then I have added in all the news specific OG tags and altered our og type to
without any name space
see good example page with tags here
http://www.globalpost.com/dispatch/news/regions/asia-pacific/111206/burma-myanmar-aung-san-suu-kyi
I have not done anything to our App, not sure if I need to make any auth changes or anything as the developer page says nothing and the object isn't mine to control. ** I have a feeling this is the issue but no real proof.**
on window.load I call newsRead() seen below, like I did before. This doesn't work.
function newsRead()
{
FB.api('/me/news:reads' +
'?article=http://www.globalpost.com/$node->path','post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
I just have no idea what to try next. Any help is appreciated.
For any of the open graph actions (including built-in) you'll need the publish_actions permission, but it's still in beta at the moment and will only work for registered developers and testers of the app - I'm not aware of any other specific restrictions, but I think you're probably going to be posting 'Article' objects ( https://developers.facebook.com/docs/beta/opengraph/objects/builtin/ )

Interfacing with wall/feeds

This is the first time I'm trying to develop a facebook app so sorry in advance if my question is too naive.
What I need to do is making a chat-like facebook application where:
the user can write something on the wall
the app should be able to detect this event and send an HTTP request to an external web service of my own which will provide a response (text)
publish that text as a comment
the user should be able to continue the dialog by entering another comment(s) (in which case we go back to step #2)
Basically, this would be very similar to:
https://www.facebook.com/SkyscannerFlightSearch
I think one (ugly) way to do this would be making a script which searches for new wall entries/comments and posts replies in an infinite loop by using the Graph API but it's obviously sub-optimal and expensive.
Is there any way to have facebook call a certain url every time a wall post/comment is entered?
Or maybe something like Twitter's streaming API based on long-polling technique?
Am I in the right direction by assuming such kind of solutions or I'm totally missing the point?
Thanks in advance.
Giampaolo
I am working on something very similar myself.
So far i have the "loop" which can be set to any page, group or app on facebook.
SAMPLE: https://shawnsspace.com/plugins/wallfeed.php My page wall.
SAMPLE: https://shawnsspace.com/plugins/wallfeed.php?pageid=19292868552&ptype=feed&limit=40 Facebook Platform Wall.
With some perms, a form and user access_tokens i can make the wall postable. Asper UGLY - you do not need to run this in a loop, Facebook supports realtime updates and will send a response to your app when a user, or page has made a change.
MORE: http://developers.facebook.com/docs/api/realtime
Thanks for the input.
I tried to use the real-time API by using object=user and fields=feed.
If I understood the doc correctly this should result in my callback url being called (POST) every time a user writes something on my app's wall.
I received the initial GET request but never POST.
This is the current configuration:
{
"data": [
{
"object": "user",
"callback_url": "http://XXX.XXX.XXX.XX:8888/",
"fields": [
"feed"
],
"active": true
},
{
"object": "page",
"callback_url": "http://XXX.XXX.XXX.XX:8888/",
"fields": [
"picture"
],
"active": true
}
]
}
I've noticed various user comments reporting different concerns about the reliability of this API.
Also, here:
http://developers.facebook.com/docs/reference/api/page/
it says: "Note: Real-time updates are not yet supported for the total number of Page checkins."
...which I'm not sure what it means exactly.
For the record, my app's page I'm using for tests is:
http://www.facebook.com/pages/testgiamp/187148861354102?sk=wall