How to get Page Photo with the most likes & comments? - php

I'm using the Facebook PHP SDK to try and get the photo with the most number of likes for a Page, to be able to use as a "hero photo". The logic being that the photo with the most likes & comments is the most interesting to look at.
However, the only method I can think of is slow and cumbersome.
Is there a better method than using the below?
1. Query the Graph API for the albums belonging to a Page
2. Query the Graph API for Photos in each Album
3. Add the likes & comments for each photo
4. Re-order the list of photos and return the best few
As you can see it's a lot of work for a relatively low payoff, but I can't think of a better way to return the most popular photo of a given Page.
Any suggestions?

It seems this is the only way to retrieve this information.
I would recommend placing this series of queries in a cron job that runs periodically and updates a static file containing the results. Then you can just source that file and not have to run the queries for each user. If each user were to execute this batch of queries your application would be extremely slow or have a large load time...

Related

Facebook Marketing - Story Image

When creating a Facebook Campaign though UI (Business Manager) there's a way to set an alternative picture for a group, so for example you can set different dimensions picture to display in the stories. However when creating same campaign using API calls, looks like there's no way for doing so? I can only have one image for an Ad Creative.
Can someone point me towards a right direction? Code sample or just an explanation of what objects needs to be created in order to achieve the result?
Here's what I'm writing about when having it about image-groups whet using Facebook UI:

Concerning the post picture size of facebook page/group feed by Graph Api

I am displaying feed/posts of facebook page/group via graph api in my site by calling this Url in php code -
https://graph.facebook.com/page_id/feed?access_token=token_value
Then, Among many type of posts, for a post of picture type i get picture url as
http://photos-g.ak.fbcdn.net/hphotos-ak-frc3/t1.0-0/1972372_10152261154160659_883879121_s.jpg
Now it's the small size as the last part "_s.jpg" indicates.But i want all picture sizes be large.So to achieve this what parameters are needed to include in the graph api url - "https://graph.facebook.com/page_id/feed?access_token=token_value" so that all picture/video type of posts' picture will be in large size??, so is there will be "_b.jpg" at last as i presume.Is that possible in one graph api call?
I searched through the google but no luck, but ended up planning that i would replace the last part of the pic url above with "_b.jpg" so that url will be like -
http://photos-g.ak.fbcdn.net/hphotos-ak-frc3/t1.0-0/1972372_10152261154160659_883879121_b.jpg
But are there any drawbacks for this hack?? what are the correct ways to achieve if possible in one graph api call.
notice,
/page/feed?fields=attachments
this will give you all of the attachments in their full sizes. worked charms for me
You could use a FQL query to get the source info of the large versions of the photos use in a Page's feed:
SELECT pid, object_id, src_big, src_big_width, src_big_height FROM photo WHERE object_id in (SELECT attachment.media.photo.fbid FROM stream WHERE source_id={page_id} AND actor_id={page_id})
Not sure if that’s actually documented somewhere – but in Graph API Explorer, the “Search for a field” feature suggests a field called full_picture. A few quick tests suggest that for most feed items, it returns the original image that was used making the post, whether it was a picture uploaded with the post, a video thumbnail or whatever.
You can use it in your feed calls like this:
/{user-or-page-id}/feed?fields=full_picture,message,type,…
Only fields you will get by default when using the fields parameter are id and created_time, everything else you might be interested in (message, type, from, etc.) you will have to ask for specifically as well.
That is for any type of feed item that might have a picture attached – expect for type:photo. For those, you get an object_id as well, and when you query that explicitly in a second request, you get an images data structure, that lists the different image sizes Facebook has on their CDN.
I have not found a wya to make it spit out that additional info within the original /foo/feed request in one go though – but if you collect all object_id that call delivers, you can use them in a second call like this to get the info for multiple objects at once:
/?ids=object_id1,object_id2,…&fields=images
with every feed there is a node name object-Id, use this id like this
graph.facebook.com/object-id/picture?type=large
if it shows question mark photo then use access_token=XXXXXX in query string.

Saving image with GD Handle

I am currently working on a website which will be used for displaying scores in several benchmarks. In order to accomplish this, i am using PHP(duh :D) for the database queries and the JPGraph library, which creates the graph and then displays and it as an image with the GD library.
The user of the site can select which chart he wants to see with a <form> that contains the following criteria:
The Client that ran the test
The Operating System the Client used at the time
The Benchmark that was used
And what type of chart he wants to see (Bar graph, line graph....)
All of this works fine, the graph is displayed without a problem in the <iframe> that it is supposed to be in.
However, I also want the user to be able to save the Graph, with, say a second button. I can get the GD handle of the image, but how can I use this to save the image to a file on the client?
Any help would be very welcome.
Regards, Andy

Adding facebook profile picture to high scores table using PHP

I was able to make a small flash game after receiving a lot of help here at Stackoverflow, I was able to post the score variable to a php file and then to database , now I would like to make a small high score list and I know I would need to use the FB users and scores previously saved to the database’s table, my question is how could I add the profile picture thumbnail besides each user’s score ? Should I save another parameter to the database or should I use the following line when I print the databse info in the html file ?
<img src="https://graph.facebook.com/<USER_ID>/picture"/>
I’m really sorry if this is a silly question, I’m really inexperienced with facebook stuff. Thanks!
This is indeed the best way to display profile photos of your users (or any users). There is no need to store URL's or even download the images to your server. All you need is the users Facebook ID.
If the pictures are those of the users friends, the chances are that they already have those images cached in their browser so it's a good idea to take advantage of that.
You can also add some parameters to that call to get other sizes of the profile picture -
https://graph.facebook.com/UID/picture?type=large
The values that are accepted are -
small
normal
large
square

Flickr API PHP getPhotoSets Description

I'm trying to integrate the Flickr API with Jquery Gallerific. If you're familiar with Gallerific you know photos in the Gallery can have a caption. I'm trying to pull photos from a specific set from a user using flickr.photosets.getPhotos to get thumbnails. However, with this method it's not possible to get description for each thumbnail, only for the set so I'm having to run flickr.photos.getInfo for each photo in the set, which works but is pretty much useless as a page takes 10+ seconds to load. Does anyone know how to obtain flickr photos from a set with the individual description for each photo? I've looked through the API but can't seem to find anything.
Thanks in advance!
Never actually used the Flickr API but what about just loading the thumbnails initially, then using JSONP (or a custom "proxy" of sorts) to query photo information asynchronously after the page has loaded. Or, better yet, when the user actually hovers over an image.

Categories