![](/img/trans.png)
[英]How to migrate from the Provisioning API to the Admin SDK API?
[英]Converting from GoogleApp Provisioning API to new SDKs
仅仅通过为Provisioning API生成XML代码块,然后使用VBScript进行POST,我们已经创建和管理GoogleApps帐户已有两年了。 现在,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编程经验。)
谢谢你的帮助!!
使用Admin SDK的步骤非常相似。 首先,您将获得身份验证,现在Google使用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/ )
我知道这是很多信息,希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.