3

I'm developing the GMail Add-on that pulls out all user's contacts to card:

var contacts = ContactsApp.getContacts();

I already enabled ContactsAPI in Google API Console and added scope: https://www.googleapis.com/auth/contacts.readonly

But the error is still there and the Contacts API is missing in the project's Advanced Google Service pop-up.

MMM
  • 103
  • 13

2 Answers2

2

Through trial and error, and this hard-to-find list I managed to get ContactsApp.getContacts() to work. You need to add this scope:

"oauthScopes": [
  "https://www.google.com/m8/feeds",
wulftone
  • 1,628
  • 1
  • 18
  • 34
  • How should I enable ContactsApp in google sheets? I want to use it just for a custom function. The error I get in the google sheet is: "Exception: You do not have permission to call ContactsApp.getContact. Required permissions: https://www.google.com/m8/feeds (line 2)." – Mateusz Dorobek Oct 01 '22 at 15:24
0

There is no need to enable Contacts API and set the scope when using the ContactsApp. When using this, upon reviewing the permission to be used, your app will automatically select the necessary permission for ContactsApp to work properly.

I've use the same code as yours:

function myFunction() {
  // The code below will retrieve all the user's contacts
 var contacts = ContactsApp.getContacts();

  Logger.log(contacts)
}

Here is the result I received:

enter image description here

Kindly check and review your code, you might have missed something.

Hope this helps.

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91
  • So, something else is enabled. May be your add-on is verified? Which scopes are enabled in your app? – MMM Nov 13 '17 at 13:45
  • This isn't the case for Gmail add-ons, unfortunately. There appears to be no automatic discovery mechanism (yet?). Does anyone know the actual scope required? – wulftone Nov 13 '17 at 18:33
  • Actually I ran into this issue because I overwrote my app manifest doing Gmail add-on development and defined OAuth scopes there. In this case I wasn't prompted by Google because it couldn't auto-detect the required scopes. Solution is to manually add the OAuth scope(s) as in @wulftone 's answer – cody.codes Mar 10 '19 at 04:33