【问题标题】:Getting Gmail User Inbox All Emails获取 Gmail 用户收件箱中的所有电子邮件
【发布时间】:2019-10-24 03:26:38
【问题描述】:

我在使用 Gmail API 获取用户收件箱电子邮件时遇到问题。 基本上我的身份验证有问题,我不知道在请求电子邮件之前如何进行身份验证。

我已经在 Google 开发者控制台中注册了我的应用并为我的应用创建了 outh2Client Id。并为此应用启用了 Gmail Api。

这是我的清单权限

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

这是我的 build.gradle 文件

    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'pub.devrel:easypermissions:0.3.0'
    implementation 'com.google.api-client:google-api-client- 
    android:1.23.0'
    implementation 'com.google.apis:google-api-services-slides:v1-rev294- 
    1.23.0'
    implementation 'com.google.api-client:google-api-client:1.25.0'
    implementation 'com.google.apis:google-api-services-gmail:v1-rev104- 
    1.25.0'
    implementation 'com.android.volley:volley:1.1.1'

这是我获取所有消息的尝试

    String url="https://www.googleapis.com/gmail/v1/users/
    mudassirktk41@gmail.com/messages";
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.GET,url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("respos",response);

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

            Log.d("respos",error.toString());

        }
    }){
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Authorization", "OAuth 533655669585-79ors38egmiuj4ct3afcsfcv08lhegh6.apps.googleusercontent.com");
            return headers;
        }


    };

    requestQueue.add(request);

我的代码总是给出错误“com.android.volley.AuthFailureError”。

【问题讨论】:

    标签: android gmail-api


    【解决方案1】:

    您可以按照HERE 的规定使用适用于 Android 的 G Suite API。还有你的依赖:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:25.0.1'
        compile 'com.google.android.gms:play-services-auth:15.0.1'
        compile 'pub.devrel:easypermissions:0.3.0'
        compile('com.google.api-client:google-api-client-android:1.23.0') {
            exclude group: 'org.apache.httpcomponents'
        }
        compile('com.google.apis:google-api-services-<API>-<VERSION>') {
            exclude group: 'org.apache.httpcomponents'
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 2017-06-09
      • 2014-10-10
      • 2017-05-15
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多