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 is
https://www.google.com/h9/feeds/profile/default and 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