title: Unable to consume JAVA sdk for Google classroom API's getting PERMISSION_DENIED Request had insufficient authentication scopes
body: <p>I am trying to integrate google classroom in my java project Using OAuth 2.0 for <strong>Server to Server</strong> authentication, example is given here <a href="https://developers.google.com/classroom/quickstart/java" rel="nofollow noreferrer">Official Google class room integration doc</a> uses <strong>OAuth consent screen authentication</strong>, I altered the code  for <strong>Server to Server</strong> authentication with few changes</p>
  
  <p>Progress so far:</p>
  
  <ul>
  <li>Created a Google App </li>
  <li><p>Enabled Google classroom API from Dashboard.</p></li>
  <li><p>Created Service Account Key (.p12) for server-to-server authentication(later used that in code along with Application name)</p>
  
  <pre><code>public class Quickstart2 {
      private static final String APPLICATION_NAME ="MY_APP_NAME";
      private static final JsonFactory JSON_FACTORY =
          JacksonFactory.getDefaultInstance();
      private static HttpTransport httpTransport;
  
      /** Global instance of the HTTP transport. */
      private static HttpTransport HTTP_TRANSPORT;
      private static final String SERVICE_ACCOUNT_EMAIL = "ID_CREADED_ON_GOOGLE_APP";
      /** Global instance of the scopes required by this quickstart.
       *
       * If modifying these scopes, delete your previously saved credentials
       * at ~/.credentials/classroom.googleapis.com-java-quickstart
       */
      private static final List&lt;String&gt; SCOPES =
          Arrays.asList(ClassroomScopes.CLASSROOM_COURSEWORK_ME);
  
      static {
          try {
              HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
          } catch (Throwable t) {
              t.printStackTrace();
              System.exit(1);
          }
      }
  
      /**
       * Creates an authorized Credential object.
       * @return an authorized Credential object.
       * @throws IOException
       * @throws GeneralSecurityException 
       */
      public static Credential authorize() throws IOException, GeneralSecurityException {  
          /* Added this code in given sample code for Server-to-server authentication*/
  
  
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes(SCOPES)
            .setServiceAccountPrivateKeyFromP12File(new File("BULB-1cb9e145138b.p12"))
             .setServiceAccountUser("bulb-88@bulb-173512.iam.gserviceaccount.com") 
            .build();
        return credential;
      }
  
      /**
       * Build and return an authorized Classroom client service.
       * @return an authorized Classroom client service
       * @throws IOException
       * @throws GeneralSecurityException 
       */
      public static com.google.api.services.classroom.Classroom
              getClassroomService() throws IOException, GeneralSecurityException {
          Credential credential = authorize();
          System.out.println("token   "+credential.getAccessToken());
          return new com.google.api.services.classroom.Classroom.Builder(
                  HTTP_TRANSPORT, JSON_FACTORY, credential)
                  .setApplicationName(APPLICATION_NAME)
                  .build();
      }
  
      public static void main(String[] args) throws IOException, GeneralSecurityException {
          // Build a new authorized API client service.
          com.google.api.services.classroom.Classroom service =
              getClassroomService();
  
          Course course = new Course()
          .setName("10th Grade Biology")
          .setSection("Period 2")
          .setDescriptionHeading("Welcome to 10th Grade Biology")
          .setDescription("test descriptioon")
          .setRoom("301")
          .setOwnerId("me")
          .setCourseState("PROVISIONED");
           course = service.courses().create(course).execute(); /* here I am getting the exception */
  
  
         //  List the first 10 courses that the user has access to.
  
          ListCoursesResponse response = service.courses().list()
              .setPageSize(10)
              .execute();
          List&lt;Course&gt; courses = response.getCourses();
          System.out.println(courses);
          if (courses == null || courses.size() == 0) {
              System.out.println("No courses found.");
          } else {
              System.out.println("Courses:");
              for (Course course1 : courses) {
                  System.out.printf("%s\n", course1.getName());
              }
          }
      }
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>I belive nothing is wrong with authentication because whenever I run this piece of code, get an entry in dashboard on my app "<a href="https://console.developers.google.com/apis/dashboard" rel="nofollow noreferrer">https://console.developers.google.com/apis/dashboard</a>"</p>
  
  <p><a href="https://i.stack.imgur.com/KoPJz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KoPJz.jpg" alt="here is the image of what I am getting on dashboard"></a></p>
  
  <p>I am new to Google class room and Its been a long time I am trying to integrating this no success so far, need help.</p>
  
  <p>One more thing It says it is mandatory to have a G suite account (I dont get it where it is used, yet I have not created G suit account, is this the reason I am getting exception)</p>
  
  <p>Please let me know If I am suppose to add more details on above senerio.</p>
  
  <p>Thanks in advance</p>