Invalid Frob means I cannot get Auth Token

Topics: Developer Forum, User Forum
Apr 19, 2008 at 12:05 PM
I am new to FlickrNet and cannot get the sample programs working at all. I have a valid API key and Secret and have used these with the Java API without a problem.
To save me pulling out what is left of my hair, Can someone help me please.

I originally was trying the sample code as is but the UploadPicture method just returned a null. So I have changed the code to get an Auth token but this code now throws "Invalid Frob". I am using VS2005, Vista Business

Here's the code I am trying to get working:

Flickr flickr = new Flickr(FlickrKeys.ApiKey, FlickrKeys.Secret);

string Frob = flickr.AuthGetFrob();
string url = flickr.AuthCalcUrl(Frob, AuthLevel.Write);

Auth auth = flickr.AuthGetToken(Frob); // Throws Invalid Frob Exception HERE. A Frob is returned.

flickr.ApiToken = auth.Token;

string title = "Test Upload";
string description = "Test Description";

string photoId = flickr.UploadPicture(Filename.Text, title); // This was returning null and not uploading so I added the Auth code above to try and fix it.

Coordinator
Apr 19, 2008 at 3:16 PM
 string Frob = flickr.AuthGetFrob();
string url = flickr.AuthCalcUrl(Frob, AuthLevel.Write);
 
Auth auth = flickr.AuthGetToken(Frob); // Throws Invalid Frob Exception HERE. A Frob is returned.

The above lines need to be split up. You MUST use the URL you have calculated to send the user to the Flickr web site. Only once they have physically approved your frob can you then use it to get the token.

 string Frob = flickr.AuthGetFrob();
string url = flickr.AuthCalcUrl(Frob, AuthLevel.Write);
System.Diagnostics.Process.Start(url);
 
Console.WriteLine("Press Enter once authenticated");
Consoel.ReadLine();
 
Auth auth = flickr.AuthGetToken(Frob); // Throws Invalid Frob Exception HERE. A Frob is returned.
Apr 19, 2008 at 3:27 PM
Thanks for the quick response.

What I am actually trying to do here is create a utility to display and upload photos from my own account. I am not writing an app for others to use.

I feel that I'm using the wrong style of authentication as why would I want to authenticate myself!

All this came about when the UploadPicture returned null and did not upload the photo, with no exception raised. All I need is a code snippet that works and uploads the photo.
Coordinator
Apr 19, 2008 at 4:37 PM
In that case you only need to do the authentication once - output the Authentication Token, and reuse it next time (i.e. no need for a Frob).

Flickr flickr = new Flickr(FlickrKeys.ApiKey, FlickrKeys.Secret, myToken);
Apr 19, 2008 at 6:26 PM
OK, now I have it!! Thanks very much. Works a treat.
Apr 20, 2008 at 8:16 AM
OK, I tried the theory of saving the token (in a class with static properties called FlickrKeys) and it failed with "Unknown Auth Token" again.
I'm trying to get this component working on a server and it would be impossible to keep having to get authorised every time the component wants to
access Flickr. Funny thing is the Upload works with the same Keys and Token.

My suspicion is that I must get a Token for each operation, Read, Write etc unless the .AuthCalcUrl call to get the token can take multiple AuthLevel options.
I suspect not as it's not declared with the Flags attribute. Is this a correct assumption?

Code from the sample slightly modified with keys from the static object.

private void GetPhotoButton_Click(object sender, EventArgs e)
{
Flickr flickr = new Flickr(FlickrKeys.ApiKey, FlickrKeys.Secret);

Auth auth = flickr.AuthCheckToken(FlickrKeys.Token); // EXCEPTION HERE. Invalid Auth Token

PhotoSearchOptions options = new PhotoSearchOptions(auth.User.UserId);
options.SortOrder = PhotoSearchSortOrder.DatePostedDesc;
options.PerPage = 1;

Photos photos = flickr.PhotosSearch(options);

Flickr.FlushCache(flickr.LastRequest);

Photo photo = photos.PhotoCollection0;

webBrowser1.Navigate(photo.SmallUrl);

OldTitle.Text = photo.Title;
PhotoId.Text = photo.PhotoId;
}
Apr 20, 2008 at 4:00 PM
OK, I now understand how the permissions work, so I granted Delete permssion to my app, copied the Token from the Authentication into my Flickr Keys class and used it to try to do a search as per the previous. Still get

Auth auth = flickr.AuthCheckToken(FlickrKeys.Token); // EXCEPTION HERE. "Invalid Auth Token (98)"

However, I CAN STILL UPLOAD using the same token.

I really need help here as I'm on a tight deadline to get this working (academic not commercial). Any more help is welcome.
Thanks