I have a little problem, I don't know how to create the script (with PHP SDK) which check if is the user a fan of my page.
I successfly get the permission for user_likes, but I cant post data to array and after check it.
When I dump this code: $user_likes = $facebook->api('/me/likes'); I'll got all data, but I cant post them to array.
It's amazing what one can find on the internet these days if only he tries to Google his questions...
Here's the first result I got for "facebook is the user a fan":
http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/
It discuss a few options, PHP and JavaScript, Graph API and REST API, just pick your favorite.
FB.api("me/likes/270801249647033", function(response) {
if ( response.data.length == 1 ) {
// Has liked
} else {
// Not liked
}});
Source and download script
From: http://developers.facebook.com/docs/reference/rest/pages.isFan/ (yes, this is deprecated, but it includes the new Graph API way to do things at the top of it. :) )
You can now issue a HTTP GET request to /USER_ID/likes/PAGE_ID (aka /me/likes/PAGE_ID ) to check if a user is a page of a fan.
Related
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.
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]&method=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.
I'm making a simple Facebook app that posts updates to the user's timeline using node.js and Facebook's Open Graph API. Even though I can see the posts I make using the OG API on my timeline (and it has the globe icon identifying that it's a public post, see pic below), none in my FB friend network can see it.
Here's a screenie of a public post I made via OG API showing up on my timeline, along with a post from a 3rd party app (Pool practice) for comparison:
Now here's the screenie of my friend's timeline showing only the Pool Practice post, the post from my app is nowhere to be seen...
I've checked the app settings and permissions as well as the OG API options, but haven't seen anything that points to how I can solve this problem. Here's the node.js code I'm using to post the updates:
// app permissions set to 'publish_actions' and 'publish_stream'
// I do the auth dance here to get the access_token and store it in session as fb_token
var request = require( 'superagent' ); // module from TJ Holowaychuk similar to "request"
request
.post( 'https://graph.facebook.com/me/feed?access_token=' + req.session.fb_token )
.send( { message: 'posting via node.js' } )
.set( 'Content-Type', 'application/x-www-form-urlencoded' )
.end( function( response ) {
log( response );
});
The code above works and the post shows up on my timeline, but no one else is able to see it.
Anyone know a way out of this?
you need to submit each action for Facebook validation before your friends can view it. Only users defined as developpers for the app are allowed to view those timeline messages.
I want to get the statistics of all the pages associated with my account on facebook, i have the code to get the statistics of a page, i just want to get the page id of all the pages associated with my account, how can i do this?
Please help.
Thanks.
You'll need to request the manage_pages permission (more details here), once you have the aquired the permission, all you have to do is make a request to :
https://graph.facebook.com/YOUR_FACEBOOK_ID/accounts.
The return value will be a JSON with all the pages/applications that are associated with your account.
You can also use this great tool that facebook provides - The Graph API Explorer (/me/accounts) to explore what other information you can retrieve without having to write a single line of code :P very useful.
FB.api('/me/accounts', function(response) {
for (id in response.data)
{
page = data[id];
page.id;
page.name;
}
});
You can use Javascript API to do this, read more :http://developers.facebook.com/docs/reference/javascript/
I have some code like the following in my application:
message = "Hi, #John Doe!"
postID = fb.stream.publish(
message = loader.render_to_string('wall_post.phtml', {'message':message}),
action_links = simplejson.dumps([{'text': "Check out blah", 'href': "http://blah.dev"}]),
target_id = 'nf'
)
Is there any way to represent a facebook #mention in the message string so that facebook converts it to a profile link for the mentioned user?
I've also been looking for an answer to this. The facebook website uses the format:
#[139730900025:PhotoGrabber] is awesome
to represent the links but I haven't been able to make that work. I re-posted a thread on the facebook forum under the "Stream" category since your post wasn't getting any attention:
http://forum.developers.facebook.com/viewtopic.php?id=47885
Mention it's partially available by open graph now. You can use only when posting an open graph ACTION
Check:
https://developers.facebook.com/docs/opengraph/mention_tagging/
It seems still impossible to use #mention tagging in classic feed posting via API
I'm pretty sure this is impossible at the moment. If it were posible by using the format that tam7t suggested it should work... Your best bet is asking them to add that to their api stream parser.
This is not possible at the moment, sorry.
AFAIK facebook's API does not allow this. The only approach that I know of at the moment would be to write a screen scraper to do these posts using the format described by tam7t's answer. If you use the mobile version of facebook's site (m.facebook.com) it makes it much easier.
NOTE: This might be a violation of Facebook's Application TOS.
Edit:
Here is some ruby code that will do the trick, using the Mechanize Gem
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get('http://m.facebook.com')
form = page.forms.first
# enter credentials
form.pass = 'user password'
form.email = 'user#example.com'
page = agent.submit form
# go straight to page to post on
page = agent.get("http://m.facebook.com/wall.php?id=PAGE_ID_NUM")
form = page.forms.first
form.message = "#[139730900025:PhotoGrabber] is awesome"
page = agent.submit form
NOTE: Obviously (as tiagoboldt kindly pointed out) it would be wrong to store / utilise the credentials of other people in your application. This approach would only be appropriate for making posts from a facebook account that you controlled.
That said, back to the original question of putting an #mention in a wall post, I have noticed that whilst the post and #mention go up on the wall fine, this method does not propagate the post to the mentioned user/page's wall. Not sure if that is important to you.