简体   繁体   English

从GoogleApp Provisioning API转换为新的SDK

[英]Converting from GoogleApp Provisioning API to new SDKs

We have been creating and managing our GoogleApps accounts for a couple years by simply generating a block of XML code for the Provisioning API, and then using VBScript to do a POST. 仅仅通过为Provisioning API生成XML代码块,然后使用VBScript进行POST,我们已经创建和管理GoogleApps帐户已有两年了。 Now GoogleApps is requiring that we move to the new Administrative SDKs, and I'm not understanding how, or even if, we can do something similar with the new system. 现在,GoogleApps要求我们迁移到新的管理SDK,而我不了解我们如何,甚至无法对新系统执行类似的操作。

Here is an example of the code we use to first get an authentication token: 这是我们首先用于获取身份验证令牌的代码示例:

' Create and send XML message to GoogleApps requesting Authentication Token
Set objXMLHTTP = CreateObject("Microsoft.XmlHttp")
objXMLHTTP.open "POST", "https://www.google.com/accounts/ClientLogin", FALSE
objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXMLHTTP.send "&Email=Administrator%40company%2Ecom%2Eedu&Passwd=P@ssw0rd&accountType=HOSTED&service=apps"
If Err.Number <> 0 Then
  WScript.Echo "Error: send request for GoogleApp Authentication Token failed"
  WScript.Quit(1)
End If
' Get response from GoogleApps
strGGAATAuthToken = objXMLHTTP.responseText
If Err.Number <> 0 Then
  WScript.Echo "ERROR: Getting GoogleApp Authentication Token (XMLHTTP.responseText) "
  WScript.Quit(1)
End If
' Check for known errors in response text
If LCase(Left(strGGAATAuthToken, 6)) = "error=" Then
  WScript.Echo "ERROR: GoogleApp replied with Error when asking for Authentication Token"
  WScript.Quit(1)
Else
  ' Extract and return Authentication Token from response text
  strGGAATToken = Mid(strGGAATAuthToken, InStr(strGGAATAuthToken, "Auth=") + 5)
  GetGAAuthToken = True
End If

Here is a sample of the code we then use to create the account: 以下是我们用来创建帐户的代码示例:

  ' Create XML Record that will be sent to GoogleApps
  strXMLRecord = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & _
                 "?>" & vbCRLF
  strXMLRecord = strXMLRecord & "<atom:entry xmlns:atom=" & Chr(34) & "http://www.w3.org/2005/Atom" & Chr(34) & _
                 vbCRLF
  strXMLRecord = strXMLRecord & "  xmlns:apps=" & Chr(34) & "http://schemas.google.com/apps/2006" & Chr(34) & _
                 ">" & vbCRLF
  strXMLRecord = strXMLRecord & "    <atom:category scheme=" & Chr(34) & "http://schemas.google.com/g/2005#kind" & _
                 Chr(34) & vbCRLF
  strXMLRecord = strXMLRecord & "      term=" & Chr(34) & "http://schemas.google.com/apps/2006#user" & Chr(34) & _
                 "/>" & vbCRLF
  strXMLRecord = strXMLRecord & "    <apps:login userName=" & Chr(34) & strCGAAUsername & Chr(34) & vbCRLF
  strXMLRecord = strXMLRecord & "      password=" & Chr(34) & strCGAAPwd & Chr(34) & vbCRLF
  strXMLRecord = strXMLRecord & "      changePasswordAtNextLogin=" & Chr(34) & "true" & Chr(34) & vbCRLF
  strXMLRecord = strXMLRecord & "      suspended=" & Chr(34) & "false" & Chr(34) & "/>" & vbCRLF
  ' The following line is just so we have the syntax if we need to set quotas
  '*****strXMLRecord = strXMLRecord & "    <apps:quota limit=" & Chr(34) & "2048" & Chr(34) & "/>" & vbCRLF*****
  strXMLRecord = strXMLRecord & "    <apps:name familyName=" & Chr(34) & strCGAALastName & Chr(34) & " givenName=" & _
                 Chr(34) & strCGAAFirstName & Chr(34) & "/>"
  strXMLRecord = strXMLRecord & vbCRLF & "</atom:entry>" & vbCRLF
  ' Create XML object, set headers, and send to GoogleApps      
  Set objXMLHTTP = CreateObject("Microsoft.XmlHttp")
  objXMLHTTP.open "POST", "https://apps-apis.google.com/a/feeds/company.com/user/2.0", FALSE
  objXMLHTTP.setRequestHeader "Content-type", "application/atom+xml"
  objXMLHTTP.setRequestHeader "Authorization", "GoogleLogin auth=" & strGAAuthToken
  objXMLHTTP.send strXMLRecord
  If Err.Number <> 0 Then
    WScript.Echo "ERROR: unable to XMLHTTP.send for GoogleApps acct creation"
    CreateGAAccount = False
    WScript.Quit(1)
  End If
  ' Get response from GoogleApps
  strResponseText = objXMLHTTP.responseText
  If Err.Number <> 0 Then
    WScript.Echo "ERROR: unable to get objXMLHTTP.responseText during GoogleApps acct creation"
    CreateGAAccount = False
    WScript.Quit(1)
  End If
  ' If response reports an error exit function returning False
  If InStr(Lcase(strResponseText), "errorcode=") <> 0 Then
    WScript.Echo "ERROR: unable to create GoogleApps account"
    CreateGAAccount = False
    WScript.Quit(1)
  End If
  ' Log GoogleApps account information returned from creation
  WScript.Echo "GoogleApp account created for: " & strCGAAUsername

It's probably obvious, but I have a Windows background, not Linux; 这也许很明显,但是我有Windows背景,而不是Linux。 and I've done scripting, but not real programming. 而且我已经完成了脚本编写,但没有完成真正的编程。 (And I have no experience doing Java and/or other Web programming at all.) (而且我完全没有Java和/或其他Web编程经验。)

Thanks for any help!! 谢谢你的帮助!!

The steps to use the Admin SDK are very similar. 使用Admin SDK的步骤非常相似。 First you will get authenticated, now google uses Oauth 2 here you can find the documentation on that https://developers.google.com/accounts/docs/OAuth2 here you can test how Oauth works: https://developers.google.com/oauthplayground/ 首先,您将获得身份验证,现在Google使用Oauth 2,您可以在这里找到https://developers.google.com/accounts/docs/OAuth2上的文档,在这里您可以测试Oauth的工作方式: https//developers.google。 COM / oauthplayground /

After being authenticated you can now call the Directory API to create a new user. 通过身份验证后,您现在可以调用Directory API创建新用户。 Here is the documentation related to the insert method https://developers.google.com/admin-sdk/directory/v1/reference/users/insert 这是与插入方法https://developers.google.com/admin-sdk/directory/v1/reference/users/insert相关的文档

As you can see in the Doc, you will be sending the same parameters (name, password, etc.) but now it won't be formatted as xml, instead those parameter will be formatted as json (here is a little information on json formatting: http://www.w3schools.com/json/ ) 正如您在Doc中看到的那样,您将发送相同的参数(名称,密码等),但是现在它不会被格式化为xml,而是将这些参数格式化为json(有关json的一些信息)格式: http//www.w3schools.com/json/

I know it's a lot of information, I hope it helps. 我知道这是很多信息,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM