Hi,

You do not need to obtain a token directly if you are using one of our
client libraries.  The client libraries will obtain the token behind
the scene and should be transparent to you.

Also, please double check that you have the Provisioning API enable,
and that you are using Google Apps Premier or Education Editions.

Information on how to enable the Provisioning API:
http://code.google.com/apis/apps/faq.html#howenable

Cheers,
Julian.

On Jan 13, 9:31 pm, Dino <[email protected]> wrote:
> I tried connecting to Google's server and getting a token, but I get
> an error: The remote server returned an error: (403) Forbidden.
> The userName, passwords, domain, adminEmail, adminPassword are hard
> codded. Can somebody suggest corrections to the code below:
>
> using System;
> using System.Text;
> using System.IO;
> using Google.GData.Apps;
> using Google.GData.Client;
> using Google.GData.Extensions;
> using System.Web;
> using System.Net;
> using System.Diagnostics;
>
> namespace GoogleProvisioning
> {
>     class googleupdate
>     {
>         private static string domain;
>         private static string adminEmail;
>         private static string adminPassword;
>
>         public static string userName = "XXXX";
>         public static string passWord = "XXXXXX";
>
>         private static void UserOperations(AppsService service)
>         {
>             // Restore the user.
>             UserEntry restoredEntry = service.RestoreUser(userName);
>             Console.WriteLine("Restored user {0}",
> restoredEntry.Login.UserName);
>
>             // Query for a single user.
>             UserEntry entry = service.RetrieveUser(userName);
>             Console.WriteLine("Retrieved user {0}",
> entry.Login.UserName);
>
>             // Query for a page of users.
>             UserFeed feed = service.RetrievePageOfUsers(userName);
>             entry = feed.Entries[0] as UserEntry;
>             Console.WriteLine("Retrieved page of {0} users, beginning
> with '{1}'", feed.Entries.Count,
>                 entry.Login.UserName);
>
>             // Query for all users.
>             feed = service.RetrieveAllUsers();
>             entry = feed.Entries[0] as UserEntry;
>             Console.WriteLine("Retrieved all {0} users in the domain,
> beginning with '{1}'",
>                 feed.Entries.Count, entry.Login.UserName);
>
>             // Update the user's given name.
>             restoredEntry.Name.GivenName = "John";
>             UserEntry updatedEntry = service.UpdateUser(entry);
>             Console.WriteLine("Updated user with new given name
> '{0}'", updatedEntry.Name.GivenName);
>         }
>
>         private static void RunSample(AppsService service)
>         {
>             try
>             {
>                 // Demonstrate operations on user accounts.
>                 UserOperations(service);
>             }
>             catch (AppsException a)
>             {
>                 Console.WriteLine("A Google Apps error occurred.");
>                 Console.WriteLine();
>                 Console.WriteLine("Error code: {0}", a.ErrorCode);
>                 Console.WriteLine("Invalid input: {0}",
> a.InvalidInput);
>                 Console.WriteLine("Reason: {0}", a.Reason);
>             }
>         }
>
>         public static void Main()
>         {
>                 domain = "XXXXXXX";
>                 adminEmail = "XXXXX";
>                 adminPassword = "XXXXX";
>
>                 AppsService service = new AppsService(domain,
> adminEmail, adminPassword);
>
>                 GetSecurityToken(adminEmail, adminPassword);
>                 RunSample(service);
>
>          }
>
>         static string GetSecurityToken(string adminEmail, string
> adminPassword)
>          {
>             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=" +
> adminEmail + "&Passwd=" + adminPassword + "&service=apps&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 " + adminEmail);
>
>                      }
>                  }
>              }
>
>              // Clean up the streams.
>
>              reader.Close();
>              dataStream.Close();
>              response.Close();
>              return Auth;
>          }
>     }
>
> }
>
> On Jan 13, 2:32 pm, Dino <[email protected]> wrote:
>
> > Can somebody submit code example for a .Net solution c# class with
> > methods for getting an Authentication Token and updating a users
> > password?
--~--~---------~--~----~------------~-------~--~----~
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