In google spreadsheet I see in the address bar that my doc url is https://docs.google.com/spreadsheet/ccc?key=0AuQ7FOvczgvFdHVzRXFKLTF1dHM5dk1qR1VzNGFDNGc#gid=0
However, when I write Browser.msgBox(SpreadsheetApp.getActiveSpreadsheet().getUrl()); in the script I get the following url
https://docs.google.com/spreadsheet/ccc?key=tusEqJ-1uts9vMjGUs4aC4g
Why is there a discrepancy? Which one should I be using for my integrations?
Turns out Google keeps different IDs for the spreadsheet and for the document entity and the one displayed in the address bar is the doc id.
So if you want to get the doc id you should do the following:
Hopefully this will help someone.