Google Apps脚本:如何编辑Xml以发送到配置文件API更新

时间:2013-03-21 19:52:11

标签: xml google-apps-script google-profiles-api

我正在尝试使用google脚本更新域用户,我已成功通过Google Profile API检索用户,但之后我需要调用更新操作,我需要通过修改发送Xml。 / p>

我正在使用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()));
}

1 个答案:

答案 0 :(得分:1)

抱歉@ Escobar5,我没有得到您的更新。 Romain Vialard有一个开源的ProfilesApp库(以及我的位)https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/profiles-services