Part 26: Retrieving a Photo from Flickr's API

Sign in to queue

The Discussion

  • User profile image
    manpreet

    hi,
    I want to develop an application which uploads users photographs to a remote server. for eg there is a photo called pic.jpg. now I want to upload this to www.abc.com/images folder. how can I do that??

  • User profile image
    rcroeder

    the url for the json2.csharp should not have the period

    RC

  • User profile image
    BobTabor

    @manpreet: You have a few options, but that is a large topic, to large for me to cover here.  Either Angel build FTP into your app, or (b) see what you can accomplish with WCF, or ( c ) perhaps you can use an Azure service + API like this article discusses:

    http://www.windowsazure.com/en-us/develop/mobile/tutorials/upload-images-to-storage-dotnet/

  • User profile image
    BobTabor

    @rcroeder: Thank you, fixed it in the TEXT version (above).

  • User profile image
    wsantosf

    The image below the following text is wrong:

    "... and paste it (carefully) beneath the Class definition for the MainPage class, but inside the AroundMe namespace like so:"

  • User profile image
    kushal bhatia

    hii,
    i want to built an app which can access my geolocation and give me near by ATM machine address and also direction for that ??
    how can i do that ???

  • User profile image
    BobTabor

    @wsantosf: Thanks, I'll look into that.

    @kushal bhatia: Yikes ... I suppose that's possible, but I have no idea how to go about it.  Sorry!  Sad

  • User profile image
    RandomAlec

    Ok, I'm having an issue that is really driving me crazy and I can't figure it out.

    I followed the video and text of this lesson many times over up to the part where we run the emulator at 25 minutes, but my emulator cuts out right before it displays the data I need.

    When it cuts out it then points to my

    string flickrResult = await client.GetStringAsync(baseUrl);

    and then states that the HttpRequestException was unhandled by user code.

  • User profile image
    Clint

    @RandomAlec: use a breakpoint at that line, hover over baseUrl and verify that Url works in an actual web browser and you are returning data.

  • User profile image
    Clint

    @RandomAlec: betting it may be the flickr API key, verify you are using your own personal one.

  • User profile image
    fatal1ty

    I have the same problem as RandomAlec. I have verified that the baseUrl works and that I put my own API Key.

  • User profile image
    RandomAlec

    @Clint: My API key is definitely correct, I checked many times over before posting my comment. I will try the Url in an actual web browser to check it.

     

  • User profile image
    Clint

    @fatal1ty: @RandomAlec: are you guys including lat / long?  Bob did make a mistake that he points out in the end of part 27 that I caught after the videos were made.

    Lat / Long must be rounded to 5 or less decimal points for Flickr's API to work.  Bob used the emulator with a location set which rounds to 4 so he never ran into this.

    If this doesn't solve your issue, zip up your solution and file a bug at https://absolutebeginner.codeplex.com/workitem/list/basic and I'll take a quick look to see what is happening.

  • User profile image
    Jurgen

    Hi Bob and all others,
    I am new to C# and phone developing, using german visual studio.

    In the german version of visual studio, I had the problem, that decimal numbers are returned with a comma, insteed of a point.
    (Like 41,12334 not 41.12334)
    The flickr api always returns invalid value for lat/long.

    So I looked around in the internet and found a way which worked
    for me.


    I did it like this, the rounding I included too :

    string str_lat = Math.Round(gpsCoorCenter.Latitude,5).ToString(CultureInfo.InvariantCulture.NumberFormat);

    string str_long = Math.Round(gpsCoorCenter.Longitude,5).ToString(CultureInfo.InvariantCulture.NumberFormat);

    After I passed this results to the url.

    Cheers
    Jurgen


  • User profile image
    BobTabor

    @Jurgen: Thank you, awesome tip!

  • User profile image
    Denis

    Hi!
    Flickr request returns an empty result when uri doesn't contain a text argument. I pass an empty value (text='') then it works.
    Thanks!

  • User profile image
    Abdallah

    Thanks Mr.Bob for this awesome tutorial .

    it works when i put "&text=a" on the url or any letter ..

  • User profile image
    Tomek

    @Bob thank you for great tutorial!<br>Does anyone get same error as me during package installation ?Install failed. Rolling back...
    Install-Package : Failed to add reference to 'System.IO'.
    At line:1 char:1
    + Install-Package Microsoft.Net.Http
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

  • User profile image
    Clint

    @Tomek: My gut says you need to update Nuget.  This post has the steps to do it.  https://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/Part-17-Introducing-the-Coding4Fun-Toolkit

    1. Go to the Tools Menu –> Extensions and Updates
    2. Go to the Update Tab –> Visual Studio Gallery

      nugetUpdate
    3. Click Update
    4. Restart Visual Studio
  • User profile image
    Heena Buddhadev

    hi,
    I want to develop an application which uploads users photographs to a Flickr.com.

  • User profile image
    Clint

    @Heena Buddhadev: awesome!  check out http://www.flickr.com/services/api/ for how to use their APIs.

  • User profile image
    Tomek

    @Clint, Thank you it helped!

  • User profile image
    devlife3
  • User profile image
    Clint
    @devlife3: dude, that is awesome! Nice find
  • User profile image
    Sheshu

    Hi Bob,

    i am playing with the json web services and i got an issue with https certificate. My server lets say, something.net is using something.com's certificate and i have to ignore and retrieve the data. Is there any way to do that in windows phone 8?

  • User profile image
    Clint

    @Sheshu: we're supporting only the lessons here, for that question, head over to the forums on https://dev.windowsphone.com or www.stackoverflow.com

  • User profile image
    sanjay

    Hi,

    I am getting below exception.
    "A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll

    If there is a handler for this exception, the program may be safely continued."

    if ,my key seems to be alright. if I use the URl to the explorer then it seems to work:" asking me to save or open rest.json...?" .

    I also used the method UpdateMap() as it is from the sample solution and changed my key. I see the same issue.
    any clue here please?

    Sanjay

  • User profile image
    Sanjay

    adding additional information:

    the above exception happens during the execution of the line:
    string flickrResult = await client.GetStringAsync(baseUrl);

  • User profile image
    Vyshali

    Thanks Bob, Clint and Larry for this amazing video series :) I hope I'm not asking a silly question.. but how did you come up with URL construction? Thanks!

  • User profile image
    Clint
    @sanjay: something else is happening. I would set a break point near when you try to open up / write to a file.
  • User profile image
    Clint
    @Vyshali: I looked at Flickr API documents which we link to. Since it is a RESTful API, it is very easy to build out the URL like we did.
  • User profile image
    sanjay

    HI Client,

    Thanks for saying some this else is happening.
    really the internet connection in the emulator was missing. I shifted to new place for winter vacation but I didn't set up the internet connection.

    Now it works.

    Sanjay

  • User profile image
    MongolZ

    Hi Clint,
    I get 404 Exception when tried to connect to flickr (the same as for example RandomAlec). However, I went mad and restarted my PC, and after that it worked. Any clue what happened? I did not change anything.

    Another issue, the Replace(",","%2C") method is not working, my license string contains the same commas, so I had to hard-code them. Don't know really why.

  • User profile image
    MongolZ

    Shame on me, the Replace method works well. Forget that.

  • User profile image
    Jas

    Sir,
    I have almost tried everything. But Flickr Image is not displaying in image box. Please help me.

  • User profile image
    Jas

    Problem Solved. I was using flicker instead of flickr in photoUrl

  • User profile image
    ahmed shabaan

    hi,
    your code run first time and when run it again throw exception

  • User profile image
    ahmed

    I'm watched last part of video and problem not solved and I have the same Bug :'(

  • User profile image
    Stephan

    Excellent tutorials, I guess you could also use the JSON output of Flickr to generate the class with Json2csharp. But my main question is why don't you use sperate folders. I.e. A folder for the classes (like the FlickrData-class) or even better a sperate project for the Flickr classes and methods, so you can use it in some other projects later. Or is this out of scope? Just wondering.

  • User profile image
    mheffels

    @BobTabor:I had the same issue as @Jurgen, but fixed it a by hardcoding the CultureInfo in formatting of the base URL, like so:

     var baseUrl = string.Format(new CultureInfo("en-US"), url, etcetc

     

  • User profile image
    Patrick

    @BobTabor: These tutorials are awesome. I know its a year later, but I'm really struggling. I have a JSON string with lists inside lists inside lists. and I'm unable to dig down through these layers with your method of deserialization. I can only get to the second layer. I tried using dictionaries and expandoObject (which seems to give the right structure) but I can't get at the data. Is there an easy way to dig maybe 4 arrays down?

  • User profile image
    Patrick

    I was not stipulating which branch to go down and so it was confused.

    System.Diagnostics.Debug.WriteLine(apiData.jobsByDateList[0].jobsList[0].interestLevel);


    I was trying to get in using

    System.Diagnostics.Debug.WriteLine(apiData.jobsByDateList.jobsList.interestLevel);

    like your example and intellisense was freaking out.

    With the [0] I'm now able to drill in just fine and don't need the expandoobject. Just needed to sleep on it. :-)

  • User profile image
    nguyen

    Hi Bob,

    I want to search some animated gif images from Flickr. Because uploaded images had been resized and converted, they cannot animate. Only orignial size images can animate. But I don't know how to get the original size images in the json result. How can I do this?

    Thanks

  • User profile image
    milincjoshi

    hi Bob,

    I am facing an issue regarding an exception 404. I followed alll of your instructions but when i run the app it throws following Exception :-

    "An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.ni.dll but was not handled in user code

    Additional information: Response status code does not indicate success: 404 ()."

    i am stuck here for nearly a week. Kindly help me with this error

  • User profile image
    Archana

    Image is not getting displayed. I 've put a breakpoint on setting imagesource line and checked the uri in webbrowser. It displayed the image. But in app its not getting displayed

  • User profile image
    Ramakrishna Ganesh

    Could anyone please help me to show a POINTER(Push Pin) at the location on a map using map control/maps task ?

Add Your 2 Cents