代码之家  ›  专栏  ›  技术社区  ›  Gourav

Blogger API始终返回401错误响应

  •  1
  • Gourav  · 技术社区  · 7 年前

    我用 Volley 在我的Android应用程序中发送HTTP请求。我在网上找了很多答案,但什么也找不到。


    我使用Blogger API并发送 HTTP 请求使用文档中提供的“按URL获取博客”方法获取我的博客

    得到 https://www.googleapis.com/blogger/v3/users/self/blogs
    授权:/*这里是OAuth 2.0令牌*/

    我在中正确添加了授权头 getHeaders() 文件中规定的正确方法:

    @Override
    public Map<String, String> getHeaders() {
        HashMap<String, String> params = new HashMap<>();
        params.put("Authorization", "My_Auth_Key");
        return params;
    }
    

    另外,正如您所看到的,我在谷歌API控制台中正确地完成了设置过程。我添加了我的包名,即, gq.gouravkhunger.blogger 和应用程序的 SHA Fingerprint 正确地: Google API console image

    但是当我测试应用程序时,我总是会得到这个错误:

    Android Debugging Volley 401 error

    1 回复  |  直到 7 年前
        1
  •  3
  •   JideGuru    7 年前

    您确定您的OAuth密钥有效吗? 还要确保您没有在应该使用OAuth的地方使用apikey。 阅读文档以更好地理解

    您可以从中获取OAuth密钥 OAUTH Playground 用于测试