我必须说这方面的文件确实令人困惑。我想从数据存储区获取数据,并收到以下错误:
04-27 18:48:40.951: W/System.err(1678): com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
04-27 18:48:40.951: W/System.err(1678): {
04-27 18:48:40.951: W/System.err(1678): "code" : 401,
04-27 18:48:40.951: W/System.err(1678): "errors" : [ {
04-27 18:48:40.951: W/System.err(1678): "domain" : "global",
04-27 18:48:40.951: W/System.err(1678): "location" : "Authorization",
04-27 18:48:40.951: W/System.err(1678): "locationType" : "header",
04-27 18:48:40.951: W/System.err(1678): "message" : "com.google.appengine.api.oauth.OAuthRequestException",
04-27 18:48:40.951: W/System.err(1678): "reason" : "required"
04-27 18:48:40.961: W/System.err(1678): } ],
04-27 18:48:40.961: W/System.err(1678): "message" : "com.google.appengine.api.oauth.OAuthRequestException"
04-27 18:48:40.961: W/System.err(1678): }
04-27 18:48:40.961: W/System.err(1678): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
我正在使用OAuth,我在我的终端中定义了我的Android设备:
public class Constants {
public static final String WEB_CLIENT_ID = "bvye4g73g7.apps.googleusercontent.com";
public static final String ANDROID_CLIENT_ID = "biurgf8ery8.apps.googleusercontent.com";
public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
}
@ApiMethod(name = "listCars", scopes = { Constants.EMAIL_SCOPE }, clientIds = {
Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID }, audiences = { Constants.ANDROID_AUDIENCE })
我已按照以下步骤创建了我的Android客户端ID:https://developers.google.com/appengine/docs/java/endpoints/auth#Java_Specifying_authorized_clients_in_the_API_backend
我不明白。我已在我的Google App Engine应用程序上定义了我的Android客户端,并将其ID设置为端点。我不明白什么不起作用。有什么建议吗?
答案 0 :(得分:0)
您的终端是否经过身份验证?如果是,您需要通过提供客户授权来验证您的呼叫: https://developers.google.com/appengine/docs/java/endpoints/consume_android#Java_Making_authenticated_calls
您需要在Android应用中选择一个Google帐户。仅当您通过在终端方法的参数中添加User来进行经过身份验证的呼叫时才需要:
@ApiMethod(name = "scores.insert") public Score insert(Score score, User user) throws OAuthRequestException, IOException { ... }