The user will have to go through AuthSub a least once.
However, after they've linked there account and you have
an AuthSub session token, save that token in your database.
The token itself is associated with a user (and their profile).

In the sample, you should only have to link the profile once.
Upon returning to the page, the token is saved as a session
variable.

Eric

On Aug 26, 8:12 am, Echo Tung <[EMAIL PROTECTED]> wrote:
> Hi Eric,
>
> I have copied down the HealthProfile.aspx codes and converted into
> ASP.net 2.0, I can get the profile information but I need to click on
> the button 3 times to get the information.  Based on the
> documentation, there are two ways to authenticate the user: Client
> Login or AuthSub.  From the sample codes, I was prompted to login to
> Google Health, but I'd like to get the token for that user so the user
> can get in without prompting their username and password.  Here are
> the codes I modified and I don't see where I can specify the user
> profile.  Please advise where and what I need to change to.  Thanks.
>
> protected void Button4_Click(object sender, EventArgs e)
>     {
>
>         if (Session["token"] != null)
>         {
>             PrintProfile();
>         }
>         else if (Request.QueryString["token"] != null)
>         {
>             String token = Request.QueryString["token"];
>             Session["token"] =
> AuthSubUtil.exchangeForSessionToken(token, null).ToString();
>             Response.Redirect(Request.Url.AbsolutePath, true);
>         }
>         else
>         {
>
>             String authSubLink = AuthSubUtil.getRequestUrl("http",
> "www.google.com", "/h9/authsub", Request.Url.ToString(), 
> "https://www.google.com/h9/feeds/";, false, true);
>             authSubLink += "&permission=1";
>             //GotoAuthSubLink.NavigateUrl = authSubLink;
>             Response.Redirect(authSubLink);
>         }
>     }
>
> protected void PrintProfile()
>     {
>         GAuthSubRequestFactory authFactory = new
> GAuthSubRequestFactory("weaver", "exampleCo-exampleApp-1");
>         authFactory.Token = (String) Session["token"];
>         HealthService service = new
> HealthService(authFactory.ApplicationName);
>         service.RequestFactory = authFactory;
>         HealthQuery profileQuery = new 
> HealthQuery("https://www.google.com/h9/feeds/profile/default";);
>         profileQuery.Digest = true;
>         try
>         {
>             HealthFeed feed = service.Query(profileQuery);
>             foreach (HealthEntry entry in feed.Entries )
>             {
>                 XmlNode ccr = entry.CCR;
>                 if (ccr != null)
>                 {
>                     Response.Write("<pre>");
>                     StringWriter sw = new StringWriter();
>                     XmlTextWriter xw = new XmlTextWriter(sw);
>                     xw.Formatting = Formatting.Indented;
>                     ccr.WriteTo(xw);
>
> Response.Write(HttpUtility.HtmlEncode(sw.ToString()));
>                     Response.Write("</pre>");
>                 }
>             }
>         }
>         catch (GDataRequestException gdre)
>         {
>             HttpWebResponse response =
> (HttpWebResponse)gdre.Response;  //bad auth token, clear session and
> refresh the page
>             if (response.StatusCode == HttpStatusCode.Unauthorized)
>             {
>                 Session.Clear();
>                 Response.Redirect(Request.Url.AbsolutePath, true);
>             }
>             else
>             {
>                 Response.Write("Error processing request: " +
> gdre.ToString());
>             }
>         }
>     }
>
> On Aug 22, 1:22 pm, "Eric (Google)" <[EMAIL PROTECTED]> wrote:
>
> > Hi Echo,
>
> > I'm more than happy to give you pointers, but it would be best to
> > keep the questions related to the Google Health API rather
> > than Calendar.  Note, there _are_ some outdated pages on this
> > forum that discuss starting out with Calendar, but it would
> > be more to your advantage if you dive straight in to the Health API.
>
> > --
> > To get started with the Health API in .NET, please see our
> > documentation 
> > at:http://code.google.com/apis/health/developers_guide_dotnet.html
>
> > and download the ASP sample 
> > at:http://code.google.com/p/googlehealthsamples/source/browse/#svn/trunk...
>
> > That should be all you need to get started :)
> > --
>
> > If you have more questions about the Calendar API, you can find
> > a .NET
> > protocol guide for Calendar 
> > here:http://code.google.com/apis/calendar/developers_guide_dotnet.html
>
> > and their forum 
> > here:http://groups.google.com/group/google-calendar-help-dataapi
>
> > Thanks,
> > Eric
>
> > On Aug 22, 6:57 am, Echo Tung <[EMAIL PROTECTED]> wrote:
>
> > > Hi Eric,
>
> > > Thanks for pointing that out, I'm learning from trial and error here.
> > > I have changed the code and now I don't get any run time error after I
> > > connect without proxy.  There are couple things I tried:
>
> > > 1. I have tried to insert a calendar entry and it worked.  I have
> > > verified that in Google calendar.
> > > 2. I tried to query the calendar but it returned NULL, I don't know if
> > > I did anything wrong here.  Here are the codes:
>
> > >         CalendarService servcie = new
> > > CalendarService("CalendarSampleApp");
> > >         CalendarQuery query = new CalendarQuery();
> > >         query.Uri = new Uri("http://www.google.com/calendar/feeds/
> > > [EMAIL PROTECTED]/private/full");
> > >         servcie.setUserCredentials("username", "password");
> > >         AtomFeed calFeed = servcie.Query(query);
> > >         if (calFeed.Entries.Count > 0)
> > >         {
> > >             AtomEntry firstEntry = calFeed.Entries[0];
> > >             String myEntryTitle = firstEntry.Title.Text;
> > >         }
>
> > > Is there something that I need to change?  Appreciate your help.
>
> > > Echo
>
> > > On Aug 21, 5:42 pm, "Eric (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > > No, that URI is not correct.
>
> > > > You can either use 
> > > > 'default':http://www.google.com/calendar/feeds/default/private/full
>
> > > > or your userID:
> > > > http://www.google.com/calendar/feeds/[EMAIL PROTECTED]/private/full
>
> > > > but not booth.  You can always use 'default' in place of a userID
> > > > to reference the authenticated user.
>
> > > > Cheers,
> > > > Eric
>
> > > > On Aug 21, 10:25 am, Echo Tung <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi Frank,
>
> > > > > Now I moved my app to another PC without proxy server running (without
> > > > > connecting to my network) and I tried to pull the calendar
> > > > > information.  I got (400) Bad request error.  Is the following codes
> > > > > correct for the Uri?
>
> > > > > query.Uri = new Uri("http://www.google.com/calendar/feeds/default/
> > > > > [EMAIL PROTECTED]/private/full");
>
> > > > > Appreciate your help.
>
> > > > > Echo
>
> > > > > On Aug 21, 8:27 am, Frank Mantek <[EMAIL PROTECTED]> wrote:
>
> > > > > > all i found about this is that article:
>
> > > > > >http://www.velocityreviews.com/forums/t302174-why-do-i-get-quotthe-se...
>
> > > > > > Too my knowledge the google servers do not do this, so i am 
> > > > > > assuming  
> > > > > > your proxy server is doing that? Can you use a http tracer to 
> > > > > > figure  
> > > > > > out what the violation is? Can you use the confg file described in  
> > > > > > that article?
>
> > > > > > Frank Mantek
> > > > > > Google
> > > > > > On Aug 21, 2008, at 2:44 PM, Echo Tung wrote:
>
> > > > > > > Hi Frank,
>
> > > > > > > I applied the codes for the proxy credentials and I think I 
> > > > > > > passed the
> > > > > > >407error.  This time I got error while call service.query, here are
> > > > > > > the errors:
>
> > > > > > > Execution of request 
> > > > > > > failed:http://www.google.com/calendar/feeds/default/allcalendars/full
> > > > > > > "The server committed a protocol violation.
> > > > > > > Section=ResponseStatusLine"
>
> > > > > > > The codes I used for the uri are as follow, are they correct?
>
> > > > > > > service.setUserCredentials("[EMAIL PROTECTED]", "mypassword");
> > > > > > > query.Uri = new Uri("http://www.google.com/calendar/feeds/default/
> > > > > > > allcalendars/full");
> > > > > > > CalendarFeed resultFeed = service.Query(query);
>
> > > > > > > Thanks for your help.
>
> > > > > > > Echo
>
> > > > > > > On Aug 20, 10:08 am, Frank Mantek <[EMAIL PROTECTED]> wrote:
> > > > > > >> When you set the webproxy object, you need to specify 
> > > > > > >> credentials on
> > > > > > >> that proxy object. It has a Credentials property, so you just do
> > > > > > >> something like this:
>
> > > > > > >> WebProxy p;
> > > > > > >> ICredentials cred;
>
> > > > > > >> cred = new NetworkCredential(proxyUserName, proxyPassword);
> > > > > > >> p = new WebProxy(proxyAddressAndPort, true, null, cred);
>
> > > > > > >> There are lots of articles on MSDN about this, the WebProxy is a
> > > > > > >> standard .NET feature.
>
> > > > > > >> Frank Mantek
> > > > > > >> Google
> > > > > > >> On Aug 20, 2008, at 4:35 PM, Echo Tung wrote:
>
> > > > > > >>> Hi Eric,
>
> > > > > > >>> Looks like our proxy server will not accept the default 
> > > > > > >>> credentials.
> > > > > > >>> I think I have to explicitly provide a userid and password that 
> > > > > > >>> has
> > > > > > >>> authority.  Is there a way for me to specify the userid and 
> > > > > > >>> password
> > > > > > >>> for the proxy server?  If there is, can you share some sample 
> > > > > > >>> codes?
> > > > > > >>> Thanks.
>
> > > > > > >>> Echo
>
> > > > > > >>> On Aug 15, 7:12 pm, "Eric (Google)" <[EMAIL PROTECTED]> wrote:
> > > > > > >>>> If you're still receiving a407it's probably because
> > > > > > >>>> your CredentialCache.DefaultCredentials are incorrrect?
>
> > > > > > >>>> Your must provide the correct login credentials to your web
> > > > > > >>>> proxy before you can query a feed.
>
> > > > > > >>>> Is it possible for you to disable the proxy or try another 
> > > > > > >>>> machine?
>
> > > > > > >>>> Eric
>
> > > > > > >>>> On Aug 15, 10:23 am, Echo Tung <[EMAIL PROTECTED]> wrote:
>
> > > > > > >>>>> Hi Frank,
>
> > > > > > >>>>> These are the codes I copied from the article and modified a  
> > > > > > >>>>> little.
> > > > > > >>>>> When I tried to debug it, it always stopped at
> > > > > > >>>>> service.Query(query);.
> > > > > > >>>>> And I don't see a default proxy mentioned in the article.  
> > > > > > >>>>> Maybe I
> > > > > > >>>>> have missed somthing, can you point me the right code?  
> > > > > > >>>>> Thanks.
>
> > > > > > >>>>>         CalendarService service = new
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
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