生活在Android移动后端入门?验证错误

时间:2015-03-04 22:42:59

标签: android google-app-engine google-cloud-messaging

我从去年开始接受一个项目,该项目基于Google现已停产的“移动后端启动器”。我相信该应用程序处于工作状态,但是当在谷歌提供的网页上选择“通过客户端ID保护”设置时,它现在似乎未通过身份验证。我收到以下错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code": 401,
"errors": [
{
"domain": "global",
"location": "Authorization",
"locationType": "header",
"message": "Unauthenticated calls are not allowed",
"reason": "required"
}
],
"message": "Unauthenticated calls are not allowed"
}

运行此方法导致错误

private void listPosts(final String alertTxt) {
    // create a response handler that will receive the result or an error
    CloudCallbackHandler<List<CloudEntity>> handler =
            new CloudCallbackHandler<List<CloudEntity>>() {
                @Override
                public void onComplete(List<CloudEntity> results) {
                    //mAnnounceTxt.setText(R.string.announce_success);
                    mAnnounceTxt.setText(alertTxt);
                    mPosts = results;
                    animateArrival();
                    updateGuestbookView();
                }

                @Override
                public void onError(IOException exception) {
                    mAnnounceTxt.setText(R.string.announce_fail);
                    animateArrival();
                    handleEndpointException(exception);
                }
            };
...

我不确定在哪里/如何开始调试?

1 个答案:

答案 0 :(得分:0)

401错误通常由以下任何原因引起:

  • 过期令牌
  • 令牌撤销
  • 令牌未获得所需范围的授权
  • 使用OAuth未正确授权请求

尝试使用refreshToken()来解决过期的令牌问题