Hi th55,

You've described the symptoms of a single-use token being
invalidated after its first use.

To debug, I would start from scratch.  Clear your sessions and
revoke any outstanding tokens.  I would also try fetching a session
token using the Mt. Tabor tool:
https://h9demo.mttaboronline.com/ca/index.html

Once you've got a long-lived session token, paste it in your code
and see what that does. I'm curious if that will also give you 401
errors.

Also, the .NET client library (http://code.google.com/p/google-gdata/)
takes care of the token details for you.  It can shorten up
much of your posted code.

.NET developer's guide:
http://code.google.com/apis/health/developers_guide_dotnet.html

Eric

On Oct 6, 4:36 am, th55 <[EMAIL PROTECTED]> wrote:
> My code used to use the deprecated url  
> https://www.google.com/h9/feeds/profile/digest.
> When using this, I could provide the long life session token to Google
> anywhere from 1 to 6 times before I got the 401 unAuthorized reply
> when fetching data.  Since this url is deprecated, I changed the code
> to use the new recommeded method of the url which 
> ishttps://www.google.com/h9/feeds/profile/defaultand then setting the
> feedQuery.ExtraParameters = "digest=true"; as per other posts in the
> group.  Now, the long life session url never works more than once.
> The second time I submit the token (which is stored in session so it
> does not change), I always get the 401 unauthorized exception.  So,
> the long life token only works once for me.  I implemented the
> recovery procedure as per the best practices document which looks for
> the status "UnAuthorized", and now that recovery procedure always gets
> invoked on the 2nd (or more ) tries to fetch a document.  I've checked
> and re-checked the token to make sure that the exact same token is
> being submitted each time and it is.  I also checked that the token is
> the one returned from Google in exchange for the single use token.
> Here is the code snippet.  Any help on this would be appreciated.
>
>         public AtomFeed GetCCRDocument(string securityToken,
> GoogleAccessMode mode) {
>
>             string googleFeedImportUrl =
> App_GlobalResources.Google.Google_Feed_Import_Url_Test;
>             if( mode == GoogleAccessMode.PRODUCTION)
>                 googleFeedImportUrl =
> App_GlobalResources.Google.Google_Feed_Import_Url_Production;
>             string googleCodeName =
> App_GlobalResources.Google.Google_Code_Name;
>             string capMedApplicationName =
> App_GlobalResources.Google.CapMed_Application_Name;
>             GAuthSubRequestFactory authFactory = new
> GAuthSubRequestFactory(googleCodeName, capMedApplicationName);
>             authFactory.Token = securityToken;
>             Service service = new Service(authFactory.Service,
> authFactory.ApplicationName);
>             service.RequestFactory = authFactory;
>             FeedQuery feedQuery = new FeedQuery();
>             feedQuery.Uri = new Uri(googleFeedImportUrl );
>             feedQuery.ExtraParameters = "digest=true";
>             AtomFeed healthFeed = service.Query(feedQuery);
>             this._Utilities.ConvertAtomFeedToXmlDocument(healthFeed);
>             return healthFeed;
>         }
>
>     public bool ExchangeSingleUseTokenForSessionToken(string
> singleUseToken) {
>
>         bool returnValue = false;
>         if( !String.IsNullOrEmpty(singleUseToken)){
>             string decodedSingleUseToken =
> HttpUtility.UrlDecode(singleUseToken);
>             HttpContext.Current.Session[csGOOGLE_AUTHENTICATION_TOKEN]
> = decodedSingleUseToken;
>             NameValueCollection coll =
> this._AuthorizationAgent.ExchangeSingleUseTokenForSessionToken(decodedSingleUseToken);
>
>             if (coll["Token"] != null) {
>
> HttpContext.Current.Session[csGOOGLE_AUTHENTICATION_TOKEN] =
> coll["Token"];
>                 returnValue = true;
>             }
>         }
>         return returnValue;
>     }
>
>           public NameValueCollection
> ExchangeSingleUseTokenForSessionToken(string singleUseToken) {
>
>             string protocol =
> App_GlobalResources.Google.Default_Protocol; // "http" or "https"
>             string domain =
> App_GlobalResources.Google.Google_Default_Domain_Name; //
> "www.google.com"
>             string healthAuthorizationExchangeTokenSegements =
> App_GlobalResources.Google.SessionTokenExchangePath; // "accounts/
> AuthSubSessionToken"
>             string exchangeTokenUrl = protocol + "://" + domain +
> healthAuthorizationExchangeTokenSegements;
>             WebRequest webRequest =
> WebRequest.Create(exchangeTokenUrl);
>             webRequest.Headers.Add("Authorization", "AuthSub token=\""
> + singleUseToken + "\"");  //Critical!
>             WebResponse webResponse = webRequest.GetResponse();
>             StreamReader reader = new
> StreamReader(webResponse.GetResponseStream());
>             string replyFromGoogle = reader.ReadToEnd();
>             NameValueCollection coll =
> this._Utilities.ExtractResponseKeyValuePairs(replyFromGoogle);
>             return coll;
>         }
>         #endregion
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Health Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/googlehealthdevelopers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to