从API Explorer调用API方法时不允许范围 [英] Scope not allowed when calling API Method from API Explorer

查看:182
本文介绍了从API Explorer调用API方法时不允许范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google App Engine中有一个奇怪的行为。我正在使用Eclipse和Java进行开发,特别是使用Google Cloud Endpoints进行开发。我使用以下设置创建了一个示例API。实际上,我正在与其他许多范围合作,但我决定尝试只用一个来追踪错误。

b $ b name =adminmanagement,
version =v1,
scopes = {AdminManagement.EMAIL_SCOPE},
clientIds = {AdminManagement.WEB_CLIENT_ID,AdminManagement.API_EXPLORER_CLIENT_ID}


public static final String EMAIL_SCOPE =https://www.googleapis.com/auth/userinfo.email;
public static final String WEB_CLIENT_ID =***。apps.googleusercontent.com;
public static final String API_EXPLORER_CLIENT_ID = com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID;

在像往常一样的API方法中,我检查用户对象是否为null。

  if(user == null){
throw new OAuthRequestException(Unauthorized Access!);
}

这非常直截了当,它一直有效。但是这次它不。如果我尝试通过API Explorer调用API方法,则会出现以下错误:

  401未授权
code>

通过Eclipse Console,我可以看到以下内容:

  INFO:getCurrentUser:AccessToken;范围不允许

SDK版本是1.9.1,但atm我有另一个使用Drive API的应用程序,作品。我试着删除并创建一个新的云控制台,删除并创建一个新的App Engine应用程序,但我总是得到这个错误。顺便说一句,如果我在App Engine上部署应用程序,我会得到一个没有规范的500内部错误,并且在日志中显示没有任何内容。只是API调用没有任何错误。



这让我疯狂,我错过了什么?



编辑:错误不会发生在版本1.8.9和以下...

解决方案

这个问题神奇地解决了自己,我避难所没有改变一件事,但我不是唯一有这个问题的人,所以我认为谷歌必须有一些东西。


I have a strange behaviour in Google App Engine. I am developing with Eclipse and Java, specifically with Google Cloud Endpoints. I created a sample API with the following settings. Actually I was working with many others scopes but I decided to try with only one to track down the error.

@Api(
    name = "adminmanagement", 
    version = "v1",
    scopes = {AdminManagement.EMAIL_SCOPE},
    clientIds = {AdminManagement.WEB_CLIENT_ID, AdminManagement.API_EXPLORER_CLIENT_ID}
)

public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
public static final String WEB_CLIENT_ID = "***.apps.googleusercontent.com";
public static final String API_EXPLORER_CLIENT_ID = com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID;

In the API Method as usual I check if the user object is null.

if (user == null) {
    throw new OAuthRequestException("Unauthorised Access!");
}

This is pretty much straight forward and it always worked. However this time it does not. If I try to call the API method through the API Explorer I get the following error:

401 Unauthorized

And through the Eclipse Console I can see the following one:

INFO: getCurrentUser: AccessToken; scope not allowed

The SDK version is 1.9.1 but atm I have another application wich uses Drive API and works. I tryed deleting and creating a new Cloud Console, deleting and creating a new App Engine application but I always get this error. By the way, if I deploy the application on App Engine I get a 500 Internal Error with no specification and NOTHING shows up in the logs. Just the API call with no errors whatsover.

This is driving me crazy, what am I missing?

EDIT: The bug DOES NOT occur in version 1.8.9 and below...

解决方案

The problem magically resolved itself, I haven't changed a thing, however I wasn't the only one with this problem so I supposed Google must have fixed something.

这篇关于从API Explorer调用API方法时不允许范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆