首页 > 解决方案 > 如何从我的 Android 应用程序访问谷歌课堂 API

问题描述

我正在尝试制作一个 android 应用程序,在用户登录后从用户的谷歌课堂帐户(课程、家庭作业等)中获取信息。

感谢教程:开始将 Google 登录集成到您的 Android 应用程序中,用户可以登录,但现在我想知道如何从他的登录帐户获取 google 课堂服务。

我已经请求了必要的范围(ClassroomScopes.CLASSROOM_COURSES),这是我一直在使用的代码:

   @Override
   protected void onCreate(Bundle savedInstanceState) {

       //google sign in stuff
       GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
               .requestEmail()
               .requestScopes(new Scope(ClassroomScopes.CLASSROOM_COURSES))
               .build();

       mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

       //will return GoogleSignInAccount if user already signed in before
       GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

   }


   public void loadClassroomAndroid(View v){
       Intent signInIntent = mGoogleSignInClient.getSignInIntent();
       startActivityForResult(signInIntent, RC_SIGN_IN);
   }

   @Override
   public void onActivityResult(int requestCode, int resultCode, Intent data){
       super.onActivityResult(requestCode, resultCode, data);

       if (requestCode == RC_SIGN_IN) {
           // The Task returned from this call is always completed, no need to attach
           // a listener.
           Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
           GoogleSignInAccount account = task.getResult(Exception.class);

           //How can I get a Classroom object from this account ?
           //Or at least get a user's classroom info ?
       }
   }

标签: androidgoogle-apigoogle-signingoogle-classroom

解决方案


推荐阅读