在续订凭据和对Google帐户的应用访问权限后授权范围 [英] Authorize scopes after renewing credentials and app access to google account

查看:42
本文介绍了在续订凭据和对Google帐户的应用访问权限后授权范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题.

我正在使用JAVA中的Google App引擎开发网络应用.

I'm developping a web app using google app engine in JAVA.

我已经在网上搜索了很多问题的答案,给出了各种解决方案,但没有一个对我有用,我仍然得到:

I've searched the web and saw a lot of different answers to my problem, giving various solutions but none of them worked for me I still get:

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Insufficient Permission",
    "reason" : "insufficientPermissions"
  } ],
  "message" : "Insufficient Permission"
}

我正在尝试从我的帐户向其他电子邮件地址发送一封邮件(作为测试,从我发送给我). 我已经成功实现了表格API,但想起我必须先经过一个同意屏幕,但现在我真的不知道如何再次弹出此屏幕来永久验证范围,让我自己解释一下.

I'm trying to send a mail from my account to other email adresses (from me to me as a test). I've implemented successfully the sheets API but remembered I had to go first through a consent Screen but now I really don't know how to popup this screen again to validate scopes permanently, Let me explain myself.

我有两个凭证文件.

  1. 为了获取用户信息以确认通过Google的登录,在这里我使用一个openID连接URL,然后我会获得用户的同意屏幕.
  2. 使用Sheets API和Gmail API作为我",首先从 my 电子表格中检索数据,然后从 my 电子邮件地址发送邮件.如前所述,我已经验证了Sheets API,但无法让Gmail使用相同的凭据.
  1. for retrieving users infos to confirm sign in through Google, here I use an openID connect URL and there I user get the consent screen.
  2. use Sheets API and Gmail API as "me" to first retrieve datas from my spreadsheets and send mail from my email adress. As told before I've validated the Sheets API but can't get Gmail to work with the same credentials.

我已经测试了各种范围,添加了另一个凭证文件,但没有成功.请告诉我您是否需要一些代码.

I've tested various scopes add another credential file without any success. Please tell me if you need some code.

编辑

仅删除了我的Sheets API凭据,还删除了我的应用程序以链接到我的帐户,现在我无法弹出同意屏幕.然后我得到:

Just deleted my Sheets API credentials also removed my app fto be linked to my account and now I cannot get the consent screen to popup. and I get:

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "invalid_grant",
  "error_description" : "Token has been expired or revoked."
}

我正在使用此代码来获取凭据

I'm using this code to get credentials

private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
    // Load client secrets.
    InputStreamReader in = new InputStreamReader(new FileInputStream(new File("WEB-INF/credentials.json")));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, in);

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
            .setAccessType("offline")
            .build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

但是Google文档说:

but google documentation says:

授权信息存储在文件系统上,因此后续 执行将不会提示授权.

Authorization information is stored on the file system, so subsequent executions will not prompt for authorization.

我在哪里可以删除存储的文件系统?

Where can I delete the stored file system?

非常感谢您的帮助

推荐答案

经过数小时的混乱,我终于有了一个无法解释的解决方案.

After messing around hours and hours I've finally came with an unexplainable solution.

我从此页面

然后将我的代码更改为

return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");

对此

return new AuthorizationCodeInstalledApp(flow, receiver).authorize(null);

显示同意屏幕.

然后,在验证我的应用程序后,我收到一个NullPointerException错误,因此我将同一行改回了该行

then I after validating my app I get a NullPointerException error so I change back the same line to this

return new AuthorizationCodeInstalledApp(flow, receiver).authorize("myemail@gmail.com");

如果它不起作用(我想这是缓存问题)

and if it doesn't work (I guess that's a cache problem)

对此

return new AuthorizationCodeInstalledApp(flow, receiver).authorize("me");

不要问我为什么,但这确实起作用. 仍然欢迎您提供有关此行为的更多详细信息.

don't ask me why but that did work. Still any more detailed infos about this behaviour is welcome.

这篇关于在续订凭据和对Google帐户的应用访问权限后授权范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆