views:

242

answers:

4

Hi:

I need to be able to log users into our flickr account using the account username and passwrd. I have been searching online for quite a while now but only founds bits and pieces of an implementation. I am not experienced with Http calls at all. I need a complete example. This is the code I have so far

   HttpWebRequest http = WebRequest.Create(url) as HttpWebRequest;         
   http.Method = "POST";
   http.ContentType = "application/x-www-form-urlencoded";
   string postData = "FormNameForUserId=" + username + "&FormNameForPassword=" +  password;
   byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
   http.ContentLength = dataBytes.Length;

    using (Stream postStream = http.GetRequestStream())
    {    
        postStream.Write(dataBytes, 0, dataBytes.Length);
    }

    HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;

My main problems at this point I guess is figuring out what all the parameters are flickr requires to log "you" in.

Any suggestions are welcome

Regards, tolga

+1  A: 

Take a look at this: Flickr.net

Henk
+1  A: 

You could try using a proxy like Fiddler to inspect what your browser is sending in the login request.

The best approach though, is likely to be using the Flickr API instead. FlickNet is a .Net wrapper for the API.

Phil Ross
+1  A: 

Make sure you set http.AllowAutoRedirect = false; That was the source of 2 hours of head banging for me. Sometimes the post request returns a redirect to the home page once you've been logged in. .NET auto follows the redirect, but doesn't submit the newly acquired cookies. >.<

Shawn Simon
+1  A: 

The Flickr API requires:

API Key 
Perms (Permissions: read, write, delete) 
Frob 
API Signature

Your URL will end up looking like this:

http://flickr.com/services/auth/?api_key=[api_key]&amp;perms=[perms]&amp;frob=[frob]&amp;api_sig=[api_sig]

The easiest way to build your frob and token is with Flickr.Net. Here is some code that does that:

Flickr ourFlickr = new Flickr();

ourFlickr.ApiSecret = ApiSecret;
ourFlickr.ApiKey = ApiKey;

string signature = ApiSecret + "api_key" + ApiKey + "methodflickr.auth.getFrob";

string frob = ourFlickr.AuthGetFrob().ToString();

string url = "http://flickr.com/services/auth/?api_key=" + ourFlickr.ApiKey + "&perms=" + "read" + " &frob=" + frob + "&api_sig=" + signature;

I hope this helps. Using their API and an interface is going to be a lot easier than trying to reverse engineer their web form anyway.

Jeremy Morgan