7

Currently, I am trying to use Google Calendar's API to create a program that allows me to add stuff to my calendar, the only problem is that I don't know how to add a scope to my program. Google tells me I have to use "https://www.googleapis.com/auth/calendar" as a scope, how do I use this?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Nam
  • 89
  • 1
  • 4
  • 1
    Have you imported the package? – Saddy Nov 16 '20 at 21:25
  • I thought I imported my packages, I guess not. Just added them, Google's guide says I need to add a scope: https://www.googleapis.com/auth/calendar or https://www.googleapis.com/auth/calendar.events. How would I add the scope? – Nam Nov 16 '20 at 21:37
  • 1
    That is a totally different question now. First you had compiler errors, now you have an API usage error. Please [edit] your question and remove the solved compiler errors. Make your example code a [mcve] and include the error in your question, not in a comment. Comments may or may not be displayed initially, and usually appear by number of votes, not chronologically. – Robert Nov 16 '20 at 22:33
  • Can you please post your auth code? – Rafa Guillermo Nov 17 '20 at 08:15

1 Answers1

1

Understanding how scopes works requires that you understand a bit about how Oauth2 works.

Oauth2 is a form of authentication where by an application requests permission to access some data from a user by displaying a consent form. This consent form is populated by scopes which the application defines as the scope of access that it needs in order to run.

The Google authentication server supports a large number of scopes scopes they are split up by the API in which they are intended to access.

The Google Calendar API supports the follwing scopes. scopes

enter image description here

Assume that you are using the Google API Java client library your code should already be controlling the scopes you are sending. Look for the section that says CalendarScopes.

 GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport, JSON_FACTORY, clientSecrets,
            Collections.singleton(CalendarScopes.ALL)).setDataStoreFactory(
            dataStoreFactory).build();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449