使用GMAIL AutoForwarding创建时权限不足

时间:2018-04-16 07:48:23

标签: android google-api google-oauth gmail-api

$combinations: MyArray;

@for $i from 0 to length($combinations) {
    $class : nth($combinations, $i+1);
    .color-#{$class)} {
        background-image: url($media2 + nth($combinations, $i+1) + ".jpg")
    } 
}

错误:

String[] googleSCOPES = {GmailScopes.GMAIL_LABELS, GmailScopes.GMAIL_READONLY, GmailScopes.MAIL_GOOGLE_COM};

            GoogleAccountCredential googleAccountCredential = GoogleAccountCredential.usingOAuth2(
                    context, Arrays.asList(googleSCOPES))
                    .setBackOff(new ExponentialBackOff());
            googleAccountCredential.setSelectedAccountName(appSettings.retrieve(Params.GMAIL_ACCOUNT_NAME));
            com.google.api.services.gmail.Gmail mService = new com.google.api.services.gmail.Gmail.Builder(
                    AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), googleAccountCredential)
                    .setApplicationName("StaffConnect")
                    .build();
            ForwardingAddress address = new ForwardingAddress()
                    .setForwardingEmail(emailAddress);
            ForwardingAddress createAddressResult = null;
            try {
                createAddressResult = mService.users().settings().forwardingAddresses()
                        .create("me", address).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (createAddressResult.getVerificationStatus().equals("accepted")) {
                    AutoForwarding autoForwarding = new AutoForwarding()
                            .setEnabled(true)
                            .setEmailAddress(address.getForwardingEmail())
                            .setDisposition("trash");
                    try {
                        autoForwarding = mService.users().settings().updateAutoForwarding("me", autoForwarding).execute();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
}

1 个答案:

答案 0 :(得分:1)

  

“insufficientPermissions”

表示当前经过身份验证的用户无权通过您的应用程序执行您请求使用的操作。权限在身份验证时授予,称为范围。

Users.settings.forwardingAddresses: create请求需要具有以下范围的授权

范围

  

https://www.googleapis.com/auth/gmail.settings.sharing

您需要重新注明用户并请求额外的范围。