Reputation: 26212
I have an issue with FB Like from website. I've got two features to like, Page Posts and Page Photos. When I Like FB Post, it works, and like is counted on both Facebook Page Post and Website. But, when I try to like a photo, like counter on website increases to 1, and after a second drops to 0.
I have following configuration:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=111111111111111111111";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Like button
'<fb:like href="' + urlToLike + '" send="false" layout="button_count" width="170" show_faces="false"></fb:like>';
URLs used for Post and Photo like:
photoUrlToLike = 'http://www.facebook.com/photo.php?fbid=111111111111&set=a.502954436404881.121467.265145956852398&type=1&permPage=1';
postUrlToLike = 'http://www.facebook.com/mydummypage/posts/1111111111111111';
So my question is since users can like posts from my website, why doesn't it work for photos as well. What am I missing here?
Edit
I've found facebook photo API :
http://developers.facebook.com/docs/reference/api/photo/
And this should be fairly simple to execute but I'm unable to do this for hours now. Quoting photo api:
likes
Create
You can like a photo by issuing a HTTP POST request to PHOTO_ID/likes connection with the publish_stream permission. No parameters necessary.
Assuming my page url is :
http://www.facebook.com/dummypage
And my Photo ID is 4234234234131
. Photo is on the wall of the dummy page.
How would my post URL look like? to which Url should I make POST request to?
Upvotes: 0
Views: 869
Reputation: 71
I have recently get troubled on the same problem. After studying couple of hours, I got understand it's not the problem of my code or anything from my side. It's a small bug, even reported to facebook. Please check here: https://developers.facebook.com/bugs/530674523672388?browse=external_tasks_search_results_51fd2ae4d0e0e1621568068
Another thing important to say, question says likes works for posts but not for photos. But I got things different from that. Same problem occurs for post containing attachment of external links content and any other contents!
I have managed posting likes using the system as said in question: You can like a photo by issuing a HTTP POST request to PHOTO_ID/likes connection with the publish_stream permission. No parameters necessary. Of course, you need a valid access token for the each user to execute this properly. You can use Facebook SDK for PHP for getting access token by Authorization each user. It works for all standard object (post, photos, videos is tested properly), just need to pass a valid id of photo, post or video.
The code it simple and I have shown fake facebook like & liked (after like) button for this:
function like_std_object($object_id){
try{
$like=$facebook->api('/$object_id/likes','post'); //post a like using api
}catch(FacebookApiException $e){
return false;
}
}
function unlike_std_object($object_id){
try{
$like=$facebook->api('/$object_id/likes','delete'); //post a un-like using api
}catch(FacebookApiException $e){
return false;
}
}
Upvotes: 2