0

Je suis en train d'intégrer la classe Google dans mon projet Java en utilisant OAuth 2.0 pour serveur à serveur authentification, exemple est donné ici Official Google class room integration doc utilise OAuth consentement écran d'authentification, je modifier le code pour serveur à serveur authentification avec quelques modificationsImpossible de consommer JAVA sdk pour obtenir la demande PERMISSION_DENIED de l'API Google classe avaient des étendues d'authentification insuffisantes

progrès à ce jour:

  • a créé un Google App
  • Activé l'API de salle de classe Google à partir de Dashboard.

  • créé service Key Account (P12) pour l'authentification serveur à serveur (utilisé plus tard que dans le code avec le nom d'application)

    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<String> 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("[email protected]") 
          .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<Course> 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()); 
          } 
         } 
        } 
    

    }

I belive rien est mal avec l'authentification parce que chaque fois que je cours ce morceau de code, obtenir une entrée dans le tableau de bord sur mon application "https://console.developers.google.com/apis/dashboard"

here is the image of what I am getting on dashboard

Je suis nouveau dans la salle de classe Google et cela fait longtemps que j'essaie d'intégrer ce pas de succès jusqu'à présent, besoin d'aide.

Une chose Il dit qu'il est obligatoire d'avoir un compte de suite G (je ne l'obtenir où il est utilisé, mais je ne l'ai pas créé compte costume G, est-ce la raison pour laquelle je me fais exception)

S'il vous plaît laissez-moi savoir Si je suis supposé ajouter plus de détails sur ci-dessus senerio.

Merci à l'avance

Répondre