Auth Token Reseting

Topics: Developer Forum
Jun 11, 2007 at 10:33 PM
So my problem is simple. in this Try block my permissions seem to be set to "Write" However In between this try block and the Button3_Click event the premission resets to "None" I don't know why, or worse how to change it back to "write" without redoing the whole process.


**************************************TRY***

try
{
//flickr.AuthGetToken(tempFrob);
//Response.Write("got token");


// use the temporary Frob to get the authentication
Auth auth = flickr.AuthGetToken(tempFrob);
// Store this Token for later usage,
// or set your Flickr instance to use it.
Response.Write("User authenticated successfully");
Response.Write("Authentication token is " + auth.Token);
Response.Write(auth.Permissions);
flickr.AuthToken = auth.Token;
auth.Token = flickr.AuthToken;
Response.Write("second time:" + auth.Permissions);

}

*************************************BUTTON3*******


protected void Button3_Click(object sender, EventArgs e)
{
Auth auth = new Auth();
flickr.AuthToken = auth.Token;
auth.Token = flickr.AuthToken;
Response.Write("Start of Upload button:" + auth.Permissions);

HttpPostedFile postfile = File1.PostedFile;
Response.Write(postfile.FileName);


string title = "Test Photo";
string description = "This is the description of the photo";
string tags = "tag1,tag2,tag3";
//string photoId = flickr.UploadPicture(postfile.FileName, title, description, tags);
string photoId = flickr.UploadPicture(File1.PostedFile.InputStream, title,
description, tags, 1, 1, 1);

auth.Token = flickr.AuthToken;
Response.Write("End of Upload button:" + auth.Permissions);


//flickr.PhotosSetMeta(photoId, "New Title", "New Description");
Coordinator
Jun 12, 2007 at 9:07 AM
No offense, but the following two bits of code are complete and utter gibberish.

flickr.AuthToken = auth.Token;
auth.Token = flickr.AuthToken;

The first line above is fine, but the second line does nothing as they are already equal to each other. You say in the comments that this 'stores' the token away for later use, but it does nothing of the sort.

Auth auth = new Auth();
flickr.AuthToken = auth.Token;
auth.Token = flickr.AuthToken;
Response.Write("Start of Upload button:" + auth.Permissions);

The first line here creates a brand new blank Auth object. All the properties of the Auth object are set to their default values. Therefore auth.Token will be null and auth.Permissions will be None.

The way you should be doing this is storing the auth token in a session variable, or a cookie or something.

e.g.

Auth auth = flickr.AuthGetToken(tempFrob);
Session["token"] = auth.Token;

and then in the button click:

flickr.AuthToken = Session["token"];

I suggest you download the example web site and look at it in more detail

Sam
Jun 12, 2007 at 4:36 PM
First off the code looks all bunk just because I was trying to figure out what was going on. This bit was so that I could print out the status of the auth token. I could Not, for example do: Response.Write(flickr.AuthToken.Permissions);

flickr.AuthToken = auth.Token;
auth.Token = flickr.AuthToken;
Response.Write("second time:" + auth.Permissions);

Anyway, I'm sure there is no need for me to defend my sloppy looking code in that I am pretty lost in this API. I think I follow what you are saying, the only time that I can modify the permissions is with the auth_url = flickr.AuthCalcWebUrl(AuthLevel.Write); line of code. And then you have to store the auth token in some session variable. I was expecting this to basically happen by default I suppose, that once the flickr.AuthToken was stored with certain permissions I would be able to access it again. But i guess it is reinitialized in between somewhere.

So thanks.

Ben
Jun 12, 2007 at 5:16 PM
Scratch all that. Did what you said, working like a dream, thanks so much.

Ben