I am using the HTML5 version of Facebook Comment in my website. I have my own Facebook APP Id.
Using Graph-API, and FQL (I think this is how to do it), I want to list all the Comments posted in my website.
Example -
Page Title1
--Comment1
--Comment2
--Comment3
Page Title2
--Comment1
--Comment2
--Comment3
Page Title3
--Comment1
--Comment2
--Comment3
etc.
Please help me out.
It is possible, in two different ways, as long as you have a fixed set of sub-pages you want to fetch comments from.
If you have a large amount of sub-pages, or a variable amount, then you don't have a good scalable solution - and many have been looking for one:
Facebook fb:comments Graph API
How to display recent comments from Facebook Comments social plugin?
Facebook FQL query to return all comments against an application
Retrieve all comments with FQL by application ID
Facebook FQL query to return all comments against an application
fql query to get comment count no longer working
http://facebook.stackoverflow.com/questions/10023179/retrieve-all-the-comments-posted-using-fql
For a Fixed set of sub-pages in your website, you can either use a batch request, or an FQL query.
Batch Request
First, you need your access token. Just enter the following as a url in a browser (credit to this website ):
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET
And this is the javascript jquery code to make a batch request to fetch comments from several urls at once:
$.ajax({
url: 'https://graph.facebook.com/',
type : "POST",
data: {
access_token : 'YOUR_APP_ACCESS_TOKEN',
batch : '[ \
{"method":"GET","relative_url":"URL1"}, \
{"method":"GET","relative_url":"URL2"} \
]'
},
success: function(data) {
jdata = JSON.parse(data);
$.each(jdata, function(index,value){
jdata[index].body = JSON.parse(value.body);
console.log(value.body);
});
// Do whatever you want with jdata
}
});
FQL
inspired from this post
FB.api({
method: 'fql.query',
query: 'select text from comment where object_id in (select comments_fbid from link_stat where url="URL1" or url="URL2")'
}, function(response) {
// Do something with results
});
Conclusion
Because of this limitation of Facebook, I plan to switch to disqus.com, which apparently supports this feature (As you can see from this blog, for example. (search for 'recent comments')
Rather than list all the comments on your site, Facebook wants you to implement code to get notified when a new comment is posted anywhere on your site.
To make this happen, you have to put some Javascript into the page where the comment is posted to also notify yourself:
window.fbAsyncInit = function(){
console.log("subscribing to comment create");
FB.Event.subscribe('comment.create',function(response){
console.log("facbeook comment created: " + JSON.stringify(response));
var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
FB.Data.waitOn([commentQuery], function () {
console.log("Facebook comment: " + JSON.stringify(commentQuery));
});
});
};
Where rather than just logging the comment to the console, you would need to implement some AJAX that would send the comment back to your site where you could store the comment in your database, or send yourself an email notifying you that the comment has been posted.
Reference: Facebook Comments Plugin
Say your website is http://mywebsite.com/blog.php?id=3 and you have a facebook comments plugin on it,
you can access comments this way
https://graph.facebook.com/comments/?ids={YOUR_URL}.
{YOUR_URL} becomes http://mywebsite.com/blog.php?id=3
Example 1: (Comments plugin installed on developers facebook doc website )
website: http://developers.facebook.com/docs/reference/plugins/comments
fetch comments: https://graph.facebook.com/comments/?ids=http://developers.facebook.com/docs/reference/plugins/comments
Example 2:
website: http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/
fetch comments: https://graph.facebook.com/comments/?ids=http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/
Check this too
Sample code for pulling comments can be found on this blog post
Related
This is the java-script sample code I am using.
<script type="text/javascript">
function auth() {
var config = {
'client_id': 'your client ID HERE',
'scope': 'https://www.google.com/m8/feeds'
};
gapi.auth.authorize(config, function() {
fetch(gapi.auth.getToken());
});
}
function fetch(token) {
$.ajax({
url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json",
dataType: "jsonp",
success:function(data) {
// display all your data in console
console.log(JSON.stringify(data));
}
});
}
But this is importing both email contacts and phone contacts. Is there any option to filter in javascript to get ONLY the email contacts ?
Currently I am filtering after importing both contacts from Google .
Any help will be appreciable.
Please Note: This is not a duplicate question. Similar questions are available in stackoverflow, but are not exactly suitable for my needs.
I googled and looked around the community for quite some time but didn't find anything that serves as a direct filter that you can add in your request only to filter out email contacts. What I suggest you could do though is to group your email contacts, then retrieve the contact group by using the group parameter.
Don't know if this might be useful for you, but gonna go on ahead and include it here, be mindful about using both the query and group parameters together, found this post that says that they don't work together.
You can use q=# in your query.
It means it makes a textual search of the letter "#" in every field, and as such
returns (almost) only results with email addresses.
I want to create unpublished image post on facebook and then edit the message attached to it.
I can create an image by doing:
/me/photos
url: somewhere
published: false
caption: 'abc'
This, due to documentation should return
Struct {
id: numeric string,
post_id: string,
}
But it doesn't return post_id. If published is set to false the post_id is omitted. When I visit created photo on facebook I can edit attached caption and other parameters of the photo. But when I try to do it trough API I can only edit very limited amount of parameters, described here:
https://developers.facebook.com/docs/graph-api/reference/photo/#Updating
I also tried different approaches, of which most promising was to post unpublished photo, then create unpublished post with image attached. Since I'm trying to post to a page I'm using this endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.5/page/feed
/me/feed
caption: 'abc'
published: false
object_attachment: (id-from-previous-request)
If I could do it like this I could later edit the message, and the post would look the same as when using /me/photos normally.
I cannot do
/me/feed
caption: 'abc'
published: false
url: somewhere
Because this results with link post(and requires link parameter as well), which is different in look from image post.
I cannot figure what I am doing wrong - I just want to create unpublished post with attached image and then edit it. It's possible trough webpage, but all my attempts trough API have failed.
The related post_id for photo_id is always generated like this(for page):
page_id + '_' + photo_id
In case the photo was posted into different edge then instead of page_id corresponding id is used, for example it would be user id, if it was posted onto edge user/photos.
This behavior isn't documented anywhere where I could find it, nor it is guaranteed to work in the future. I contacted facebook support yet they didn't clarify if it's intended. They only said that it's by design that post_id is not returned.
On a search result page I would like to get the count of Google+ shares for the URL of each search result item via Ajax. I already managed to set up counting functions for Facebook and Twitter:
$.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=?', function(data){
tweets = data.count;
});
$.getJSON('https://api.facebook.com/method/links.getStats?urls='+ url+'&format=json', function(data){
fblikes = data[url].shares;
});
For Google+ I also already found a solution, but this requires the API Key for each URL. Is there any way to retrieve the Google+ count without such a key? Using it for tons of dynamically loaded search results, of course I cannot create an API key for each search result URL.
Yes, it's possible to get Google +1 counts. They are retrieved via a JSON-RPC POST call.
POST URL:
https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
POST Body:
[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]
where %%URL%% is the desired URL.
Have a look at the following:
Getting google +1 Page shares via AJAX (hidden Api)
http://www.sharedcount.com/documentation.php
I've a facebook application and I'm using a Feed and Share Dialog popup to post an image on my personal profile. My goal is to tag a friend of mine (instead of posting it on his timeline, I can not change this behaviour for a customer request - considered less spammy).
So, the question is, is there a way to tag a friend in the post? According the API of Feed and Share Dialogs it's not possible, but how can I do that?
Here's the code.
var sIdPersonalProfile = [my personal id profile];
var sIdFriendProfile = [my friend id profile];
var hFacebookData = {
method: 'feed',
display : 'popup',
name: 'NAME_APP',
caption: 'CAPTION_APP',
description: 'DESCRIPTION_APP',
picture: 'URL_APP',
to: sIdPersonalProfile
};
FB.ui(hFacebookData, callback);
thanks in advance.
Assuming you have already figured out how to POST the image to your personal profile. Then, to tag yourself or someone else is quite easy. You need to issue POST request to one of the following urls:
https://graph.facebook.com/PHOTO_ID/tags/USER_ID
https://graph.facebook.com/PHOTO_ID/tags?to=USER_ID
or, if you need to tag more than one user you need to pass an array of user ids...
'https://graph.facebook.com/PHOTO_ID/tags?tags=[{"tag_uid":"1234"}, {"tag_uid":"12345"}]`
This operations will require the following permissions are passed in the scope parameter...
user_photos
publish_stream
You can also specify some extra parameters such as the coordinates of the location of the tag in the image and a tag caption. For more info, check out the Facebook Developer Photo API to publish tags
I'm stuck with sharing and commenting Facebook posts from my website.
Look.
In Twitter we can reply a tweet simply by a link
https://twitter.com/intent/tweet?in_reply_to=35782000644194304
or
we can retweet the tweet by this link
https://twitter.com/intent/retweet?tweet_id=35782000644194304
it's so easy, after clicking you redirecting to twitter where you can do this, and i like it.
With facebook posts it is not so easy.
I have Facebook posts (copies of posts, i parsed them before and saved to my DB, ID of that posts I saved too) at my website and I'd like to share/comment/like this posts. Maybe Facebook have the links like twitter, or some another way to do it, I don't know, but i spend all day to find solution and I failed.
Maybe it is possible to create links like this:
http://facebook.com/ID_OF_THAT_FB_POST/share
or
http://facebook.com/ID_OF_THAT_FB_POST/comment
and.. after clicking the link, it redirects to facebook page, where you can share this post or comment?
Well let me see if I understand, If you want to SHARE/COMMENT/LIKE a post on Facebook, from your website then you can use the Graph API, POST, connection section.
https://developers.facebook.com/docs/reference/api/post/
This allows you to create a comment and a like, having the right access_token and the stream_publish permission.
Create:
You can write to the POST_ID/comments connection to post a comment to the post by issuing an HTTP POST request with the publish_stream permission and following parameters.
So you have yo make an HTTP POST request to http://graph.facebook.com/POST_ID/comments?message=HELLO+WORLD&access_token=YOUR_ACCESS_TOKEN
same thing for the like:
make an HTTP POST request to http://graph.facebook.com/POST_ID/likes?access_token=YOUR_ACCESS_TOKEN
with Javascript SDK would be something like this :
var postID='POST_ID';
var msg = 'Comment this post';
FB.api('/'+postID+'/comments', 'post', { message: msg }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
If you want to share the there is no API documentation for that, but you can use something like this:
<script type="text/javascript">
function sharePost(){
var page = 'https://www.facebook.com/permalink.php?story_fbid=POST_ID&id=PAGE_ID';
var sharer= 'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(page);
var w=660;
var h=460;
var sTop=window.screen.height/2-(h/2);
var sLeft=window.screen.width/2-(w/2);
var sharer= window.open(sharer,"Share","status=1,height="+h+",width="+w+",top="+sTop+",left="+sLeft+",resizable=0");
return false;
}
</script>
<a onclick="sharePOST()">SHARE POST</a>
Do not think facebook yet has such kind of api, though you may look up the iframe url structure for any kind of social widget and try to play around. Here is the list you may look it up https://developers.facebook.com/docs/guides/web/#plugins. Take in consideration that share button is deprecated in favor of like. Also I would rather escape heavy code customization and trying to use API as much as it possible, this would help avoid future incompatibilities while facebook's evolution)