This is the Error:
Exception: Unexpected error while getting the method or property getContacts on object ContactsApp. (line 2, file "ag1")
The Original Question:
The code came from here. It's a previous answer to a question. I don't understand how I can be getting that error there.
function getAllContacts() {
var contactsA=ContactsApp.getContacts();//The Error occurs on this line
var s='';
var br='<br />';//line delimiter change to linefeed when not using html dialog
var dlm=' ~~~ ';//field delimiter
for(var i=0;i<contactsA.length;i++) {
s+=Utilities.formatString('<br />\'%s\',\'%s\',\'%s\',\'%s\',\'%s\'%s',
(typeof(contactsA[i].getFullName())!='undefined')?contactsA[i].getFullName():'',
(typeof(contactsA[i].getAddresses().map(function (v,i,A) { return A[i].getAddress();}))!='undefined')?contactsA[i].getAddresses().map(function (v,i,A) { return A[i].getAddress();}).join(dlm):'',
(typeof(contactsA[i].getEmails().map(function(v,i,A) {return A[i].getAddress();}))!='undefined')?contactsA[i].getEmails().map(function(cV,i,A) {return A[i].getAddress();}).join(dlm):'',
(typeof(contactsA[i].getPhones().map(function(v,i,A){return A[i].getPhoneNumber();}))!='undefined')?contactsA[i].getPhones().map(function(v,i,A){return A[i].getPhoneNumber();}).join(dlm):'',
(typeof(contactsA[i].getCompanies().map(function(v,i,A){return A[i].getCompanyName();}))!='undefined')?contactsA[i].getCompanies().map(function(v,i,A){return A[i].getCompanyName();}).join(dlm):'',br);
}
var ui=HtmlService.createHtmlOutput(s).setWidth(800) ;
SpreadsheetApp.getUi().showModelessDialog(ui, 'Contacts')
}
Actually, I can run the code in another spreadsheet with no errors but in the spreadsheet that I use all of the time with StackOverflow Questions it fails.
This function fails on line 2 also:
function testing101() {
const cA=ContactsApp.getContacts();
Logger.log(cA.length);
}
After Fix For UrlFetch Issue Roll Out:
Still getting the same error in this file. It still works in other files. Here's my manifest file (minus my libraries):
{
"timeZone": "America/Denver",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}, {
"userSymbol": "People",
"serviceId": "peopleapi",
"version": "v1"
}, {
"userSymbol": "Slides",
"serviceId": "slides",
"version": "v1"
}, {
"userSymbol": "Gmail",
"serviceId": "gmail",
"version": "v1"
}, {
"userSymbol": "Sheets",
"serviceId": "sheets",
"version": "v4"
}, {
"userSymbol": "DriveActivity",
"serviceId": "driveactivity",
"version": "v2"
}, {
"userSymbol": "Calendar",
"serviceId": "calendar",
"version": "v3"
}],
"webapp": {
"access": "MYSELF",
"executeAs": "USER_DEPLOYING"
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["https://mail.google.com/", "https://www.google.com/m8/feeds", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/script.container.ui", "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/gmail.send", "https://www.googleapis.com/auth/script.send_mail", "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/presentations", "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/script.projects.readonly", "https://sites.google.com/feeds", "https://www.googleapis.com/auth/drive.activity"],
"runtimeVersion": "V8"
}