To get user's profile information in google script

前端 未结 2 1043
暖寄归人
暖寄归人 2021-01-26 08:16

I want to get my domain\'s user\'s profile information..I am using profile API for this..

Profile API gives only a few fields like (Family Name, Given Name,Email etc)..B

2条回答
  •  情深已故
    2021-01-26 08:32

    I got my all fields by Profile API.... Actually if any field is empty then Profile API doesn't give that field as an output..... So using Profile API, we can get a user's full information....

    Code :
        var username="user "
        var base = 'https://www.google.com/m8/feeds/'; 
        var fetchArgs = googleOAuth_('contacts', base);
        fetchArgs.method='GET'
        var url=base+'profiles/domain/'+domainName+'/full/'+username+'?v=3&alt=json'
    
        var name=""
        var occupation=""
        var department=""
        var email=""
        var contactNumber_1=""
        var contactNumber_2=""
        var relation=""
        var account=""
        var office=""
        var personal_account=""
        var current_account=""
        var language=""
        var blog=""
        var image=""
        try{
          var urlFetch = UrlFetchApp.fetch(url, fetchArgs)   
          var json=Utilities.jsonParse(urlFetch.getContentText())
          var profileInfo = json.entry
          try{
            name=profileInfo.gd$name.gd$fullName.$t
          }catch(err){}
          try{
            occupation=profileInfo.gContact$occupation.$t
          }catch(err){}
          try{
            department=profileInfo.gd$organization[0].gd$orgDepartment.$t
          }catch(err){}
          try{
            var emaillist=profileInfo.gd$email
            for(var i=0;i

    If any field is empty then that tag will not be found thats why all the fields are written in try - catch block...

提交回复
热议问题