Authorize scopes after renewing credentials and app access to google account

女生的网名这么多〃 提交于 2019-12-12 01:09:49

问题


Here is my problem.

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"
}

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.

I have two credentials files.

  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.

EDIT

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");
}

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?

Any help is greatly appreciated


回答1:


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

I remove my app from this page

then change my code to

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

to this

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

to make appear consent screen.

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)

to this

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.



来源:https://stackoverflow.com/questions/53897514/authorize-scopes-after-renewing-credentials-and-app-access-to-google-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!