Sunday, October 28, 2007 11:53 PM mehfuzh

New LINQ provider for Flickr

LINQ provider for Flickr gives  an easy way to query , add and delete Flickr photos. Here, I will give some sneak preview about how to use the provider to do different operations on Flickr, as if doing queries with SQL objects.

Now, waiting no more, lets see, what can we do with it.

Now, Let's say, i want to get a particular user's ("chschulz") photos with "New york" as search key  and I also want only the first page, where each page should have 5 items.

The code snippet for that will be :

// create the context
FlickrContext context = new FlickrContext();
// set the user.
string user = "chschulz";
// do query.
var query = (from ph in context.Photos
             where ph.User == user && ph.SearchText == "New York" && ph.PhotoSize == PhotoSize.Thumbnail
             select ph).Take(5).Skip(0);

try
{

    foreach (Photo p in query)
    {
        Console.WriteLine(p.Title + "\r\n" + p.Url);
    }

}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Output

50th Steuben Parade
http://farm2.static.flickr.com/1067/1409243458_776fdd4f53_t.jpg?v=0
50th Steuben Parade
http://farm2.static.flickr.com/1234/1408366057_96c9498f6b_t.jpg?v=0
50th Steuben Parade
http://farm2.static.flickr.com/1236/1408380481_9df2e62351_t.jpg?v=0
50th Steuben Parade
http://farm2.static.flickr.com/1335/1408370401_f4315f2e00_t.jpg?v=0
50th Steuben Parade
http://farm2.static.flickr.com/1383/1408375435_861124b5aa_t.jpg?v=0

One thing to add,  by default when we will query without any private/semi-private view mode, result will contain only public photos.

To have Semi-private /private photos, We can set option by ViewMode enum

public enum ViewMode
{
    Owner,
    Public = 1,
    Friends,
    Family,
    FriendsFamily,
    Private
}

Note, There is a value called ViewMode.Owner, when specified , it means "get all my photos". This will get all private/semi-private photos of an authenticated account.Also, ViewMode.Private and ViewMode.Owner, will get the private photos only and all photos of a specified user respectively.

When we  will try to view or modify private/semi-private photos, The authentication process will done by API on behalf. The API will automatically , open a new browser(for windows app) / take to the URL, where the user will be prompted for valid credentials and access permission for the app, for which the photos to be viewed/deleted/added. Finally, the user will be taken back to the app, after user closes browser (windows app) / automatically (web app, we have to specify the URL of our app, in the return URL of API configuration page of Flickr).

There is also an enum for specifying Photosize

public enum PhotoSize
{
    Square,
    Thumbnail,
    Small,
    Medium,
    Original,
    Default = Medium (this is set by default)
}

In addition, the most important options for searching are:

  • Photo.SearchText : Used for specifying keyword for which Title, Description or tags will be search on.
  • Photo.User : The name of the user , of whom the photos will be queried on.

Moving forward, LINQ query for viewing single phtoto for an ID.

FlickrContext context = new FlickrContext();

var query = from ph in context.Photos
            where ph.Id == PhotoId && ph.PhotoSize == PhotoSize.Medium
            select ph;

Photo photo = query.Single<Photo>();

Next , query syntax for deleting a photo.

FlickrContext context = new FlickrContext();
var query = from ph in context.Photos
             where ph.Id == PhotoId
             select ph;

Photo photo = query.Single<Photo>();

context.Photos.Remove(photo);
context.SubmitChanges();

Any  remove or add operation must follow a FlickrContext.SubmitChanges(). This is where, the action will be posted to Flickr.

Finally, API is never done without a photo add operation. Snippet for that :-

FlickrContext context = new FlickrContext();
context.Photos.Add(
new Photo{ FileName = Path.GetFileName(uploader.Value),
File = uploader.PostedFile.InputStream, ViewMode = ViewMode.Private});
context.SubmitChanges();

Here, we have to either set the Photo.File(Stream) for uploaded file (in web app), or we can only specify  Phtoto.FilePath (windows app).

*The above , three examples are taken from Flickr.Web (test) app , which is provided with the LINQ.Flickr API at codeplex.

This is the short briefing of LINQ To Flickr API , which I have recently uploaded in codeplex, please give a look at it and let me know , how can I improve it more.

The API can be downloaded at : LINQ to Flickr API

 

kick it on DotNetKicks.com Filed under: ,

Comments

# New LINQ provider for Flickr

Sunday, October 28, 2007 12:57 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# LINQ Provider for Flickr

Sunday, October 28, 2007 8:51 PM by かるあ のメモ

New LINQ provider for Flickr(fuz's WebLog) Flickr の検索を LINQ で行える Provider が紹介されています。

# re: New LINQ provider for Flickr

Sunday, October 28, 2007 8:51 PM by kazimanzurrashid

Mehfuz it is really kool thing.

# re: New LINQ provider for Flickr

Monday, October 29, 2007 9:26 AM by Omer van Kloeten

Sweet! :D

# re: New LINQ provider for Flickr

Monday, October 29, 2007 10:41 AM by mehfuzh

Thanks, Rashid and Omer for the feedback!

 

# LINQ provider for Flickr &laquo; vincenthome&#8217;s Software Development

Pingback from  LINQ provider for Flickr &laquo; vincenthome&#8217;s Software Development

# Links from the Sharpside [10.29.07]

Monday, October 29, 2007 7:49 PM by Tales from the SharpSide

Links from the Sharpside [10.29.07]

# ca domain name &raquo; New LINQ provider for Flickr

Tuesday, October 30, 2007 1:43 PM by ca domain name » New LINQ provider for Flickr

Pingback from  ca domain name &raquo; New LINQ provider for Flickr

# busy week last week, and looks like more of the same this week

Monday, November 05, 2007 4:35 AM by Tiernans Comms Closet

Sorry for the lack of posts this week, and i am pre-empting the same this week. So, here are a few quick

# New LINQ provider for Flickr

Monday, November 26, 2007 8:02 PM by New LINQ provider for Flickr

Pingback from  New LINQ provider for Flickr

# re: New LINQ provider for Flickr

Thursday, February 07, 2008 10:49 AM by Danny Douglass

Nice job!  I have a question though - every time I try to run the Flickr.Web project with the "showOnlyMyPhotots" config vale set to "true" it brings me to the flickr page showing that I have allowed this application access.  It does work when I have the value set to false.  Thoughts?

My Photos: www.flickr.com/.../ddouglass

# re: New LINQ provider for Flickr

Sunday, February 10, 2008 1:55 AM by mehfuzh

When you set the value = true, it shows your pictures both private and public from your account and for that you must need to grant the app. In other cases (value=false, public photos), it is not required by flickr.

I am upgrading the Demo_project, so stay tuned.

# MSDN Blog Postings &raquo; LINQ to FLICKR - this is cool

Sunday, February 17, 2008 4:41 PM by MSDN Blog Postings » LINQ to FLICKR - this is cool

Pingback from  MSDN Blog Postings  &raquo; LINQ to FLICKR - this is cool

# LINQ provider for Flickr

Monday, February 18, 2008 12:27 PM by Pietro Brambati Blog

Vi segnalo questa implementazione di un provider LINQ per Flickr . Il progetto &#232; ospitato su CodePlex

# LINQ provider for Flickr

Monday, February 18, 2008 12:42 PM by Noticias externas

Vi segnalo questa implementazione di un provider LINQ per Flickr . Il progetto &#232; ospitato su CodePlex

# MSDN Blog Postings &raquo; LINQ provider for Flickr

Monday, February 18, 2008 2:21 PM by MSDN Blog Postings » LINQ provider for Flickr

Pingback from  MSDN Blog Postings  &raquo; LINQ provider for Flickr

# MSDN Blog Postings &raquo; LINQ provider for Flickr

Monday, February 18, 2008 2:28 PM by MSDN Blog Postings » LINQ provider for Flickr

Pingback from  MSDN Blog Postings  &raquo; LINQ provider for Flickr

# MSDN Blog Postings &raquo; LINQ provider for Flickr

Monday, February 18, 2008 2:34 PM by MSDN Blog Postings » LINQ provider for Flickr

Pingback from  MSDN Blog Postings  &raquo; LINQ provider for Flickr

# Linq for Flickr : tout est dans le titre

Tuesday, March 18, 2008 9:33 AM by The Mit's Blog

Un post pour satisfaire mon petit coté développeur ASP.Net qui clame pour coder autre chose que du SharePoint

# Geek Daily &raquo; Blog Archive &raquo; LINQ provider for Flickr

Friday, March 28, 2008 11:32 AM by Geek Daily » Blog Archive » LINQ provider for Flickr

Pingback from  Geek Daily  &raquo; Blog Archive   &raquo; LINQ provider for Flickr

Leave a Comment

(required) 
(required) 
(optional)
(required)