我正在尝试使用 google 脚本更新域用户,我通过 Google Profile API 成功检索了用户,但是我需要调用更新操作,并且需要发送带有我修改的 Xml。
我正在使用 Xml Services,但它们似乎只是为了阅读 xml。
如何更新我的 Xml 对象以将其发送到 Profile API 的更新操作?
这是代码:
/**
* Script configuration
*/
var SCOPE = 'http://www.google.com/m8/feeds/';
var APPNAME = "profile";
var GET_URL = 'https://www.google.com/m8/feeds/profiles/domain/{domainName}/full/{userName}?v=3.0';
function updateContact(e) {
var domain = UserManager.getDomain();
GET_URL = GET_URL.replace("{domainName}", domain);
var user = UserManager.getUser(Session.getActiveUser());
var userName = user.getUserLoginId();
var user = getUser(userName);
if(user !== null)
{
//Update
updateUser(user, '344343','432432423','test','test');
}
}
function getUser(userName)
{
try
{
var response = UrlFetchApp.fetch(GET_URL.replace("{userName}",userName) , googleOAuth_('GET'));
var jsonObj = Xml.parse(response.getContentText())
var text = response.getContentText();
var entry = jsonObj.entry;
if(typeof(entry) !== 'undefined' && entry !== null)
{
return entry;
}
}
catch(ex)
{
}
return null;
}
function updateUser(userEntry, phone, mobile, position, city)
{
var editLink = '';
var linksLength = userEntry.link.length;
for(var i=0; i<linksLength; i++)
{
if(userEntry.link[i].rel === "edit") editLink = userEntry.link[i].href;
}
//This is where I don't know what to do, how to edit the user entry
var response = UrlFetchApp.fetch(editLink,googleOAuth_('PUT', xml.toString()));
}