When you created your application in the
Google Developers Console, which type of application did you specify? The code example is designed to work with an
Installed/native application. The error suggests that your application is a Web application, in which case the redirect URI used in the example won't match your application's redirect URI. If you create and use an Installed application instead then the example should work as expected.