如何集成client_secret json文件并获取Android for google教室api的谷歌凭据

时间:2018-03-09 05:30:10

标签: android google-classroom

我想在课堂apis中集成oauth id,我从google api console下载client_secret.json用于创建android应用程序, 以前我正在通过基于电子邮件的凭据,现在我想在不询问电子邮件的情况下更改为oauth id。

这是我的代码:但这个代码我从谷歌教室apis使用java,但它不能在android.Please有人帮助我。

InputStream in =
                Sample1.class.getResourceAsStream("/client_secret.json");
        GoogleClientSecrets clientSecrets =
                null;
        try {
            clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

        } catch (IOException e) {
            e.printStackTrace();
        }

        GoogleAuthorizationCodeFlow flow =
                null;

        flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Arrays.asList(SCOPES))
                .setAccessType("offline")
                .build();

        try {
            credential = new AuthorizationCodeInstalledApp(
                    flow, new LocalServerReceiver()).authorize("user");
        } catch (IOException e) {
            e.printStackTrace();
        }

当我运行此代码时,我得到了这样的网址: ** https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=542678605378-g1h3b23dm59f8eeulbndss52dud1sr6e.apps.googleusercontent.com&redirect_uri=http://localhost:38503/Callback&response_type=code&scope=https://www.googleapis.com/auth/classroom.courses.readonly **

但实际上是访问谷歌教室的原始网址 的API: https://www.googleapis.com/auth/classroom.courses.readonly

0 个答案:

没有答案