我试图用google脚本更新域用户,我通过google Profile API成功检索用户,但随后我需要调用更新操作,并且我需要发送带有修改的Xml。
我正在使用Xml服务,但他们似乎只是为了读取Xml。
我如何更新我的Xml对象,将其发送到配置文件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()));
}
对不起@Escobar5,我没有收到你的更新。有一个开源的ProfilesApp库由Romain Vialard(和我的位)在这里https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/profiles-services