Вопрос

I'm trying to update a domain user with google scripts, I'm successfully retrieving the user through the Google Profile API, but then I need to call the update operation and I need to send the Xml with my modifications.

I'm working with Xml Services but they seem to be just for reading xml.

How can I update my Xml object to send it to the update operation of the Profile API?

This is the code:

/**
 * 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()));
}
Это было полезно?

Решение

Sorry @Escobar5, I didn't get your update. There's an open source ProfilesApp library by Romain Vialard (and bits from me) here https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/profiles-services

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top