OAuth Exception occurred: token_used

Topics: Developer Forum
Nov 19, 2013 at 2:44 PM
I've been using flickernet to build out some powershell cmdlets so I can work with my photos. Specifically I am doing batch uploads of images that have been sorted and renamed.

This past weekend I started getting the error message listed in the subject. I figured that perhaps I went over some sort of limit, so I created a new apikey and i'm still getting this error message.

Has anyone seen this before? The only thing I've not tried is to create a different flickr account and get an api key for that one.

Any help would be appreciated, thanks!
Coordinator
Nov 19, 2013 at 4:10 PM
Hard to say without seeing your code I'm afraid. I'm not familiar with the error.

Any chance you could post the part that deals with authentication?

Sam
Nov 23, 2013 at 12:02 PM
Any of the cmdlets I wrote are throwing this exception. Here is one that pulls your nsid
    public class Get_flckrNSID : Cmdlet
    {
        [Parameter(Mandatory = true, Position = 0,
            HelpMessage = "The url to the user's profile or photos page")]
        public string url;

        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            Flickr flickr = FlickrManager.GetInstance();
            OAuthAccessToken fAuth = flickr.OAuthGetAccessToken(Globals.requestToken, Globals.requestTokenSecret, Globals.verifier);
            WriteObject(flickr.UrlsLookupUser(url));
        }
    }
I've configured my apikey as a desktop app, and i run two cmdlets to get my authkey
    public class Get_flckrRequestToken : Cmdlet
    {
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            Flickr flickr = FlickrManager.GetInstance();
            OAuthRequestToken oAuthReq = flickr.OAuthGetRequestToken("oob");
            WriteObject(oAuthReq);
            Globals.requestToken = oAuthReq.Token;
            Globals.requestTokenSecret = oAuthReq.TokenSecret;
            System.Diagnostics.Process.Start(flickr.OAuthCalculateAuthorizationUrl(oAuthReq.Token, AuthLevel.Write));
        }
    }
and then to approve it
    public class Approve_flckrAuthToken : Cmdlet
    {
        [Parameter(Mandatory = false, Position = 0,
            HelpMessage = "Enter the pin code")]
        public string pinCode = "625-314-228";

        [Parameter(Mandatory = false, Position = 1,
            HelpMessage = "provide the RequestToken")]
        public string RequestToken = Globals.requestToken;

        [Parameter(Mandatory = false, Position = 2,
            HelpMessage = "Enter the RequestTokenSecret")]
        public string RequestTokenSecret = Globals.requestTokenSecret;

        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            Globals.verifier = pinCode;
            Flickr flickr = FlickrManager.GetInstance();
            OAuthAccessToken fAuth = flickr.OAuthGetAccessToken(Globals.requestToken, Globals.requestTokenSecret, Globals.verifier);
        }
    }
Nov 24, 2013 at 1:24 PM
After I modified my code to return back the response from flickr, I pasted the authtoken into the explorer (http://www.flickr.com/services/api/explore/flickr.auth.oauth.checkToken) I get back invalid token

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="98" msg="Invalid token" />
</rsp>

As, i'm just using the methods provided by flickrnet, why am I getting this error? I've tried a different api key, and a created a new user and setup a key for that and still get the same error?

did flickr change something? I have a feeling and i'm not good enough at calling rest directly, but I have a feeling that if icall directly or whatever, it will just work.
Coordinator
Nov 24, 2013 at 1:54 PM
Ah, I see problem. You can't use the same request token over and over again. Once you've used it once that is it.

You should be storing the access token in the global variables, and not the request token.
Nov 24, 2013 at 3:55 PM
That applies even on the first time I've used a new token? I'll look at what I'm doing and double-check it's not something silly. I've added your flickrmanager.cs to my project and stored the app key and secret there. Then I get a requesttoken, and the pin that comes back in the web page, I just approve it for the sessions. which feels wrong to me as well.

the flow basically is, get-flckrrequesttoken > click approve in the web interface and copy the pin > approve-flckrauthtoken using the copied pin > do flickr things, uploads, searches whatever.

I do this each time I need to work with my images in powershell...so obviously there is a better way. I was thinking that I could store the authtoken that comes back for re-use over and over, perhaps hash the output and store it in a text file, and then read it in.

honestly i'd like to do something like connect-flckrservice, do things
Coordinator
Nov 25, 2013 at 8:04 AM
You should be calling OAuthGetAccessToken once, and only once, inside approve-flickrauthtoken.
After you have received the OAuthAccessToken instance you need to be storing the access token and access token secret in the Globals variable. At this point you can blank out the request access token and secret, as they are no longer any use.

Then inside your command-let (or inside FlickrManager.cs) get the access token and the access token secret and set the appropriate properties on the Flickr instance.

Sam
Nov 25, 2013 at 2:16 PM
Thank you! I feel so completely stupid now...lol..do you think it would be possible to store that out in a file and then re-use the authtoken later? or would I always need to request authorization when using the app?
Coordinator
Nov 25, 2013 at 3:21 PM
I would definitely store it - where is up to you.

Sam