简体   繁体   English

Gmail API 403 权限不足域全局

[英]Gmail API 403 Insufficient Permissions domain global

            @Override
            protected List< String > doInBackground( Void... params ) 
            {
                try 
                {
                    //This line below is the cause of the insufficient permissions error
                    ListMessagesResponse messagesWithLabels = mService.users().messages().list("me").setQ("label:inbox").execute();

                    /*for( Message m : messagesWithLabels.getMessages( ) )
                    {
                        if( m.size( ) > MAXSIZE )
                        {
                            List<MessagePartHeader> headers = m.getPayload( ).getHeaders( );

                            for ( MessagePartHeader header : headers )
                            {
                                if ( header.getName( ).equals("From") || header.getName().equals("Date")
                                        || header.getName().equals("Subject") || header.getName().equals("To")
                                        || header.getName().equals("CC")) {
                                    messageDetails.put( header.getName( ).toLowerCase( ), header.getValue( ) );
                                }
                            }

                            messageDetails.put("snippet", m.getSnippet());
                            messageDetails.put("threadId", m.getThreadId());
                            messageDetails.put("id", m.getId());
                            messageDetails.put("body",m.getPayload().getBody().getData());

                            GmailFunctions.deleteThread( mService, "me", m.getId( ) );

                            messageDetails.clear( );
                        }
                    }*/

                    return getDataFromApi( );
                } 
                catch ( Exception e ) 
                {
                    mLastError = e;

                    cancel( true );

                    return null;
                }
            }

I have marked the line which is causing a 402 Insufficient permissions domain: global error.我已经标记了导致 402 Insufficient permissions domain: global error 的行。 If I comment out said line the program will return the labels and print them to the screen without the permissions error.如果我注释掉该行,程序将返回标签并将它们打印到屏幕上,而不会出现权限错误。 I have signed my release apk and set up the Google Play Developer console.我已经签署了我的发行版 apk 并设置了 Google Play 开发者控制台。 The app is signing just fine it's SHA1 and I followed the sample application which retrieves credentials.该应用程序的签名很好,它是 SHA1,我遵循了检索凭据的示例应用程序。

https://developers.google.com/gmail/api/quickstart/java https://developers.google.com/gmail/api/quickstart/java

What to do about insufficient permissions?权限不足怎么办?

Thank you.谢谢你。

The creation of mservice: mservice的创建:

                   private class MakeRequestTask extends AsyncTask< Void, Void, List< String > > {


                    private com.google.api.services.gmail.Gmail mService = null;

                    private Exception mLastError = null;

                    ArrayList<String> sRemovalIds = new ArrayList<String>( );

                    List< String > inserts = new ArrayList< String >( );

                    Map<String, Object> messageDetails = new HashMap<String, Object>( );

                    public MakeRequestTask( GoogleAccountCredential credential ) 
                    {
                        HttpTransport transport = AndroidHttp.newCompatibleTransport( );

                        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance( );

                        mService = new com.google.api.services.gmail.Gmail.Builder(
                                transport, jsonFactory, credential )
                                .setApplicationName( "Gmail API Android Quickstart" )
                                .build( );
                    }

                    @Override
                    protected List< String > doInBackground( Void... params ) 
                    {
                        try 
                        {
                            ListMessagesResponse messagesWithLabels = mService.users().messages().list("me").setQ("label:inbox").execute();

                            /*for( Message m : messagesWithLabels.getMessages( ) )
                            {
                                if( m.size( ) > MAXSIZE )
    private static final String[ ] SCOPES = { GmailScopes.GMAIL_LABELS, GmailScopes.GMAIL_COMPOSE,
GmailScopes.GMAIL_INSERT, GmailScopes.GMAIL_MODIFY, GmailScopes.GMAIL_READONLY, GmailScopes.MAIL_GOOGLE_COM };

Using these scopes instead of the default with only GMAIL_LABELS worked for me.使用这些范围而不是默认范围,只有 GMAIL_LABELS 对我有用。

You may also need to delete your previous credentials file after changing permissions.更改权限后,您可能还需要删除以前的凭据文件。 This is usually in $HOME/.credentials/这通常在 $HOME/.credentials/

You may also need to delete your previous credentials file after changing permissions.更改权限后,您可能还需要删除以前的凭据文件。 It's token.json in the current folder.它是当前文件夹中的 token.json。

除了@Eae提到的设置范围,删除StoredCredential文件,文件路径为your_project/tokens/StoredCredential。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当前用户权限不足google api - The current user has insufficient permissions google api Android Gmail API 获取消息 403 错误 - Android Gmail API get message 403 error Android日历api 403禁止权限不足错误 - Android calendar api 403 forbidden Insufficient permission error facebook sdk 权限不足,无法通过 Api 共享内容 - facebook sdk Insufficient permissions for sharing content via Api 用于应用内订阅收据检查的 Google Developer API(权限不足问题) - Google Developer API for in app subscription receipt check(insufficient permissions issue) UserRecoverableAuthUIException之前的GMail API授权权限 - GMail API Grant Permissions Before UserRecoverableAuthUIException 地理位置权限不足 - Insufficient geolocation permissions Glass 的 SpeechRecognizer 权限不足错误 - SpeechRecognizer insufficient permissions error with Glass Cloud Firestore:缺少权限或权限不足 - Cloud Firestore: Missing or insufficient permissions “当前用户没有足够的权限来执行请求的操作。” - Google Play 开发者 API - "The current user has insufficient permissions to perform the requested operation.” - Google Play Developer API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM