我们一直在创建和管理我们的GoogleApps帐户几年,只需为Provisioning API生成一段XML代码,然后使用VBScript进行POST。现在,GoogleApps要求我们迁移到新的管理SDK,我不了解我们是如何,甚至是否可以使用新系统做类似的事情。
以下是我们用来获取身份验证令牌的代码示例:
' 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
以下是我们用于创建帐户的代码示例:
' 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
这可能是显而易见的,但我有Windows背景,而不是Linux;我已完成脚本编写,但不是真正的编程。 (我根本没有做Java和/或其他Web编程的经验。)
感谢您的帮助!!
答案 0 :(得分:0)
使用Admin SDK的步骤非常相似。 首先,您将获得身份验证,现在谷歌使用Oauth 2,您可以在https://developers.google.com/accounts/docs/OAuth2找到文档 在这里,您可以测试Oauth的工作原理:https://developers.google.com/oauthplayground/
经过身份验证后,您现在可以调用Directory API来创建新用户。以下是与插入方法https://developers.google.com/admin-sdk/directory/v1/reference/users/insert
相关的文档正如您在Doc中看到的那样,您将发送相同的参数(名称,密码等),但现在它不会被格式化为xml,而是将这些参数格式化为json(这里是关于json格式的一些信息:http://www.w3schools.com/json/)
我知道很多信息,我希望它有所帮助。