Hi Julian,

I wish I knew about that last night!  I guess it was something with my
implementation of getting the token because the above worked fine.
Like I said before, I hope this additional AppsService Constructor
will be in the next release of the SDK for others to use.

Thanks so much everyone!


On Dec 4, 9:13 am, "Julian (Google)" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I think it would be easier to get the Authentication Token using
> the .NET Google.GData.Client.Service, for example:
>
> ...
> using
> Google.GData.Apps;
> using Google.GData.Client;
> using Google.GData.Extensions;
> using Google.GData.Extensions.Apps;
>
> ...
>
> Service service = new Service(AppsNameTable.GAppsService,
> "youAppName", AppsNameTable.GAppsAgent);
> service.setUserCredentials("[EMAIL PROTECTED]", "PASSWORD");
> String token = service.QueryAuthenticationToken();
>
> ...
>
> AppsService appsService = new AppsService("domain.com", token );
>
> Cheers,
> Julian
>
> On Dec 4, 1:28 pm, NCCFred <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi Tony,
>
> > Below is a copy of the C# Code:
>
> > I've verified that there's no white spaces and I'm not truncating the
> > Auth token when I'm doing my "Substring".  I'll be playing with this
> > today - on another note, Any chance of this Constructor making it's
> > way into the next release of the .NET API? - I think that would he out
> > a lot of Developers.
>
> > using System;
> > using System.Collections.Generic;
> > using System.Text;
> > using Google.GData.Apps;
> > using Google.GData.Extensions;
> > using Google.GData.Client;
> > using System.Web;
> > using System.Net;
> > using System.Diagnostics;
> > using System.IO;
>
> > namespace GoogleMod
> > {
>
> >     class Program
> >     {
>
> >         static void Main(string[] args)
> >         {
>
> >             UserEntry entry;
>
> >             string email = "[EMAIL PROTECTED]";
> >             string password = "XXXXX";
>
> >             string Auth = GetSecurityToken(email, password);
> >             Debug.WriteLine("Auth = " + Auth);
>
> >            AppsService service = new AppsService("students.ncc.edu",
> > Auth);
>
> >             try
> >             {
> >                 entry = service.RetrieveUser("XXXXXXXX");
> >                 Debug.WriteLine(entry.Name.FamilyName);
> >             }
>
> >             catch (AppsException e)
> >             {
> >                 Debug.WriteLine(e.ErrorCode);
> >                 Debug.WriteLine(e.Data);
> >                 Debug.WriteLine(e.Message);
> >                 Debug.WriteLine(e.Reason);
> >                 Debug.WriteLine(e.Response);
> >                 Debug.WriteLine(e.ResponseString);
> >                 Debug.WriteLine(e.Source);
> >             }
>
> >         }
>
> >         static string GetSecurityToken(string email, string password)
> >         {
>
> >             WebRequest request = 
> > WebRequest.Create("https://www.google.com/accounts/ClientLogin";);
>
> >             request.Method = "POST"; // Set the Method property of the
> > request to POST
>
> >             string postData = "accountType=HOSTED&Email=" + email +
> > "&Passwd=" + password + "&service=xapi&source=NCC-TESTAPP-1.0";
>
> >             byte[] byteArray = Encoding.UTF8.GetBytes(postData);
>
> >             request.ContentType = "application/x-www-form-
> > urlencoded"; // Set the ContentType property of the WebRequest.
>
> >             request.ContentLength = byteArray.Length; // Set the
> > ContentLength property of the WebRequest
>
> >             Stream dataStream = request.GetRequestStream(); // Get the
> > request stream
>
> >             dataStream.Write(byteArray, 0, byteArray.Length); // Write
> > the data to the request stream
>
> >             dataStream.Close(); // Close the Stream object
>
> >             WebResponse response = request.GetResponse(); // Get the
> > response
>
> >             Debug.WriteLine(((HttpWebResponse)
> > response).StatusDescription);
>
> >             dataStream = response.GetResponseStream(); // Get the
> > stream containing content returned by the server.
>
> >             // Open the stream using a StreamReader for easy access.
>
> >             StreamReader reader = new StreamReader(dataStream);
>
> >             // Read the content.
>
> >             string responseFromServer = reader.ReadToEnd();
>
> >             // Display the content.
>
> >             Debug.WriteLine("Server Responded " + responseFromServer);
>
> >             string sid = string.Empty;
>
> >             string lsid = string.Empty;
>
> >             string Auth = string.Empty;
>
> >             foreach (string token in responseFromServer.Split('\n'))
> >             {
>
> >                 if (token.StartsWith("SID="))
> >                 {
>
> >                     sid = token.Substring(4);
>
> >                 }
>
> >                 else if (token.StartsWith("LSID="))
> >                 {
>
> >                     lsid = token.Substring(5);
>
> >                 }
>
> >                 else if (token.StartsWith("Auth="))
> >                 {
>
> >                     Auth = token.Substring(5);
>
> >                 }
>
> >                 else
> >                 {
>
> >                     if (token.Trim().Length > 0)
> >                     {
>
> >                         Debug.WriteLine("Error authenticating Google
> > user " + email);
>
> >                     }
>
> >                 }
>
> >             }
>
> >             // Clean up the streams.
>
> >             reader.Close();
>
> >             dataStream.Close();
>
> >             response.Close();
>
> >             return Auth;
>
> >         }
>
> >     }
>
> > }
>
> > On Dec 3, 11:48 pm, "Tony (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > Hi Fred,
>
> > > Can you post the latest code here so I can help you take a look first?
>
> > > Thanks,
>
> > > --Tony
>
> > > On Dec 3, 8:18 pm, NCCFred <[EMAIL PROTECTED]> wrote:
>
> > > > Hi Tony,
>
> > > > I forgot to add service name and source.
>
> > > >  string postData = "accountType=HOSTED&Email=" + email + "&Passwd=" +
> > > > password + "&service=xapi&source=NCC-TESTAPP-1.0";
>
> > > > Once I did this I was able to get the "Auth" token, but I'm still
> > > > getting the same error.  I'm wondering if Julian could email me the
> > > > DLL's.
>
> > > > Error:
> > > > ---------
> > > > Google.GData.Client.GDataRequestException was unhandled
> > > >   Message="Execution of request 
> > > > failed:https://www.google.com/a/feeds/students.ncc.edu/user/2.0/intisof";
> > > >   Source="Google.GData.Apps"
> > > >   ResponseString="<HTML>\n<HEAD>\n<TITLE>Token invalid</TITLE>\n</HEAD>
> > > > \n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>Token invalid</H1>
> > > > \n<H2>Error 401</H2>\n</BODY>\n</HTML>\n"
> > > >   StackTrace:
> > > >        at Google.GData.Apps.UserService.Query(UserQuery feedQuery)
> > > >        at Google.GData.Apps.AppsService.RetrieveUser(String username)
> > > >        at GoogleMod.Program.Main(String[] args) in C:\Documents and
> > > > Settings\Administrator\Desktop\VSprojects\GoogleMod\GoogleMod
> > > > \Program.cs:line 29
> > > >        at System.AppDomain._nExecuteAssembly(Assembly assembly, String
> > > > [] args)
> > > >        at System.AppDomain.ExecuteAssembly(String assemblyFile,
> > > > Evidence assemblySecurity, String[] args)
> > > >        at
> > > > Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
> > > >        at System.Threading.ThreadHelper.ThreadStart_Context(Object
> > > > state)
> > > >        at System.Threading.ExecutionContext.Run(ExecutionContext
> > > > executionContext, ContextCallback callback, Object state)
> > > >        at System.Threading.ThreadHelper.ThreadStart()
>
> > > > On Dec 3, 8:40 pm, "Tony (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi Fred,
>
> > > > > Yes, there is really an "Auth" token in the response.  Since all three
> > > > > tokens (SID, LSID and Auth) will be returned in the response, my guess
> > > > > is that your current code logic just skips the second and third tokens
> > > > > as the first condition of the "if" statement is satisfied.  You may
> > > > > want to update your code logic and create an array to store all three
> > > > > tokens for other services.  For example, the Reporting API is using
> > > > > the SID.
>
> > > > > Thanks,
>
> > > > > --Tony
>
> > > > > On Dec 3, 5:13 pm, NCCFred <[EMAIL PROTECTED]> wrote:
>
> > > > > > Hi Julian,
>
> > > > > > Thanks for the code sample, it took me sometime to actually 
> > > > > > understand
> > > > > > exactly where this belonged. I was able to add that Constructor code
> > > > > > to the AppsService Class and recompile the project which produced 3
> > > > > > new DLL's (Extensions.dll, Client.dll and Apps.dll).  I copied these
> > > > > > to the correct location on my machine and made a small test app (see
> > > > > > code below).
>
> > > > > > Questions:
> > > > > > 1. Am I supposed to get a value for "Auth"?  The documentation says 
> > > > > > I
> > > > > > will get a SID, LSID and Auth, I do not see the "Auth".  I assumed 
> > > > > > to
> > > > > > use the SID and got the following error below when trying to
> > > > > > RetrieveAllUsers();
>
> > > > > > Exception/Error:
> > > > > > Execution of request 
> > > > > > failed:https://www.google.com/a/feeds/students.ncc.edu/user/2.0
>
> > > > > > Google.GData.Client.GDataRequestException was unhandled
> > > > > >   Message="Execution of request 
> > > > > > failed:https://www.google.com/a/feeds/students.ncc.edu/user/2.0";
> > > > > >   Source="Google.GData.Apps"
> > > > > >   ResponseString="<HTML>\n<HEAD>\n<TITLE>Token 
> > > > > > invalid</TITLE>\n</HEAD>
> > > > > > \n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>Token 
> > > > > > invalid</H1>
> > > > > > \n<H2>Error 401</H2>\n</BODY>\n</HTML>\n"
> > > > > >   StackTrace:
> > > > > >        at Google.GData.Apps.UserService.Query(UserQuery feedQuery)
> > > > > >        at Google.GData.Apps.AppsService.RetrieveAllUsers()
> > > > > >        at
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" 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/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to