Assume I have a photo gallery, with a DB something like this (a rushy mockup in Word ^_^):
I've written a rest API for it. But I'm confused about how to map a certain scenario…
/api/galleries - Lists all of the categories available
/api/galleries/:categoryID – Lists all of the galleries for this category
/api/galleries/:categoryID/:galleryID – Returns all of the info for a gallery
/api/galleries/:categoryID/:galleryID/images – Returns all images for a gallery
Now, my question is, what if I want to list ALL galleries and ALL images on a single page? As it stands, I'd have to call /api/galleries/:categoryID/:galleryID/images/ for every single gallery.
What would you think to be best practice for doing this? Maybe remove the images resource completely and just merge the images into the results for the /api/galleries/:categoryID/:galleryID query? Or maybe create a separate resource called "show-all" or something? i.e. /api/galleries/:categoryID/all/show-all and return the info combined with the images?
I'm by no means an expert on the topic, but to me your api seems flawed.
What's wrong
For example this location is lying.
/api/galleries - Lists all of the categories available
I for one would expect that it returns a list of galleries.
/api/galleries/:categoryID
Here I would expect to pass the gallery id.
What I would advice
Having a more clean api.
/api/galleries // get all galleries
/api/galleries?expand=images // get all galleries with the images
/api/galleries/:id // get a specific gallery
/api/galleries/:id?expand=images // get a specific gallery with the images
/api/galleries/categories // get all galleries categories
/api/galleries/categories/:cat // get all galleries in a category
....
By using a parameter the api doesn't get cluttered with all kind of options you might have. Keeping it clean and simple.
Here's a link to a really nice video about REST api design http://www.stormpath.com/blog/designing-rest-json-apis
Also
I don't see the need for a separate info table. It would make the database simpler if you added that info to your gallery table.
Why not using like this.
/api/galleries - Lists all of the categories available
/api/galleries/:categoryID – Lists all of the galleries for this category
/api/galleries/:categoryID/info/:galleryID – Returns all of the info for a gallery
/api/galleries/:categoryID/images/:galleryID – Returns all images for a gallery
/api/galleries/:categoryID/images – Returns all images for a all galleries
Related
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.
I am building a "Reddit" like site.
The User can post an URL from which I want to get the correct image with PHP.
What I would need is a script which sites like Facebook or Tumblr use to fetch the Images.
I saw already scripts which get the images by getting the HTML Content and searching for "img" tags.
Are there any better methods/scripts available?
Maybe even scripts which will order the images by the size: The bigger the image the more important it is.
Thanks for answers
You may want to check out PHPQuery, it will allow you easily iterate through all images on a given website. You can then work out the areas of each image and sort them accordingly.
It depends a bit for what you're looking for and what the image is that the user would like to have with his post. To give you an example: I once wrote a method that searches for a logo of a company on the company's website. To do so, I searched for, indeed, the img-tags using simple_html_dom and filtered those tags on the existence of logo in the alt-tag. The results are displayed to the user to select the right image; it could be that you find multiple images fitting your purpose.
I would indeed, as you proposed, have a look at the size and skip small images (e.g. smaller dan lets say 50 px).
I am developing a really simple PHP application to display pictures on the web.
My application is composed by a Database with two tables Image and Categories, some simple business logic and the UI.
In the UI, when the user loads the page for the first time, has a picture (randomly taken) the possibility to browse the images with left/right arrows and the possibility to choose a specific category (one picture belongs at the most to one category).
My issue is in the browsing mechanism. If I browse the image without selecting a category everything is fine. If I select a category the website correctly displays all the thumbnails of the images belonging to that category (easy query).
However if I click on one picture (it load in another page) and then navigate with the arrows the website browses all the pictures and not those beloning to the selected category. I would like instead to browse just pics in the selected category.
How can I implement this mechanism? I alwasy pass Category_Id and Image_Id (null for all pictures) to the server function but I always lose the state of the iterator in the variable containing the query elements. How can I solve this problem?
Solutions with code sample are appreciated, however it is enough to propose an implementation logic.
Thanks
Francesco
I did something similar a while back.
Assuming that you want your images displayed in image_id order you could do the following.
On the "next" link, you make a call to your PHP script with parameters that identify the category and the id and the direction you want to move.. eg
myserver.com/myapp/images.php?action=next&cat=holidaypics&image_id=111
Then you can do a query to find the next highest image_id with the same category by doing something like "select min(image_id) from images where category_id="holidaypics" and image_id > 111"
If you're going in reverse you'd change the action to "prev" and do a query like this...
"select max(image_id) from images where category_id="holidaypics" and image_id < 111"
Does that help?
Use sessions http://ru2.php.net/manual/en/book.session.php
or pass all variables your need every time you ask server.
Consider Ajax to load your container with images of a particular category.
It is as simple as saying HI
I'm trying to retrieve pictures from flickr using the Zend Framework. So far I'm successful in retrieving images based upon a tag however the result is far from what I expected.
Seems that retrieving every picture tagged by a city name also returns pictures that you wouldn't want to show on a travel site even though it has been tagged by the city name.
How does gogobot manage to retrieve the correct pictures for all the cities they have? I don't want to consider having to make my own library n flickr with pictures for all the cities and have them manually tagged.
Tagging images is user driven - so I could take a photo of me in London and tag it 'me', and 'london'. Then when you search you are also getting this image, as the api would suggest.
To only get photos you really want, you will either have to specify what images you want to fetch, or as you say, start your own library.
Also, on http://www.flickr.com/services/api/flickr.photos.search.html check out the 'accuracy' field
i'd like to add a media library to a custom-made CMS that is build on Zend Framework and Doctrine. The goal is to build something like Worpress's media library: you can upload media and then attach it to for example an article.
Do you have any suggestions how to start on this? How should the database be designed? Is there any code that i can (re-)use to build this? Is there any literature that I should read on this subject? Thanks!!
I don't know how WPs library is built, but it's Open source, you can take a look.
As for table structure, assuming you want a many-to-many link you'd want a cross reference table, something like:
record_id (int)
media_id (int)
title (text)
caption (text)
rank (int)
Then the media table would be something like:
id (int)
title (text)
caption (text)
filename (text)
type (image|multimedia|document)
Perhaps you'd also add a folder_id field to the media table, or perhaps you instead want tagging, in which case you have a third table with media_id and tag as fields (or you have tags as comma separated values in the media table).
This will let you link one media to multiple items and one item to multiple media. It'll let you set a title and caption for the media item and override it for a specific link. For instance you have a picture of a house with the caption of whose house it is, but in one link the caption is overwritten (in the cross reference table) with text saying how this house is an example of a certain architecture. SQL's coalesce function will come in handy for getting the correct title and caption.
If the content that links to media comes from multiple table, say you have a table called 'staff' and another called 'products' and they can both link to media, then the cross reference table also needs to have a table_name field. The type field is so that you can easily get only the multimedia attached to a record, or only the images; you may want to count how many documents are attached, how many images etc, basing this off the filename on each query means you have slower queries.
One thing this doesn't quite cater for is hosting the media off site. If you use say Amazon S3 for storing these images, then the 'filename' field would actually be a URL to the image. I'm just shooting this out there as something you need to take into consideration when designing the media library.
I can't think of any literature or code you can copy-paste though, it's not difficult to do, though I do appreciate this can be time consuming.
Best of luck.
write a file uploader and file browser
that's all