2013-02-24 11 views
5

sto cercando la seguente chiamata API per la mia GAE cloud Endpoint:400 risposta da GAE cloud Endpoint

gapi.client.myapp.foo.update({ 
    "value": "foobar", 
    "key": "keyvaluefromlistoperation" 
}).execute(function(resp) { 
    console.log(resp); 
}); 

che risponde con il seguente:

[ 
{ 
    "error": { 
    "code": 400, 
    "message": "Bad Request", 
    "data": [ 
    { 
    "domain": "usageLimits", 
    "reason": "keyInvalid", 
    "message": "Bad Request" 
    } 
    ] 
    }, 
    "id": "gapiRpc" 
} 
] 

nota, prima di questa chiamata mi aver autenticato, inserito diversi oggetti foo, quindi chiamare l'elenco per farli ritornare al client. La chiamata all'aggiornamento per explorer di api funziona bene e anche il frammento di jQuery in basso funziona bene. Eventuali suggerimenti? O sono solo in terra sperimentale.

var token = gapi.auth.getToken(); 
$.ajax({ 
    type:"POST", 
    beforeSend: function (request) { 
    request.setRequestHeader("Content-Type","application/json"); 
    request.setRequestHeader("Authorization", token.token_type+" "+token.access_token); 
    }, 
    url: "https://myappid.appspot.com/_ah/api/myapp/v1/foo/update", 
    data:JSON.stringify({ 
    "value": "foobar", 
    "key": "keyvaluefromlistoperation" 
    }), 
    processData: false, 
    dataType: "json", 
    success: function(msg) { 
    console.log(msg); 
    }, 
    failure: function(msg) { 
    console.log(msg); 
    } 
}); 

Ecco il codice Java:

@Api(
    name = "myapp", 
    description = "This is the myapp rest interface", 
    scopes = {"https://www.googleapis.com/auth/userinfo.email"}, 
    version = "v1", 
    clientIds = {Ids.WEB_CLIENT_ID} 
) 
public class FooV1 { 

    private static PersistenceManager getPersistenceManager() { 
     return PMF.get().getPersistenceManager(); 
    } 

    @ApiMethod(
      name = "foo.update", 
      httpMethod = HttpMethod.POST 
    ) 
    public Foo update(Foo foo, User user) throws OAuthRequestException, IOException, UnauthorizedUpdateException { 
     PersistenceManager pm = PMF.get().getPersistenceManager(); 

     if (user != null) { 
      try { 
       Foo f = pm.getObjectById(Foo.class, foo.getId()); 
       if (Security.isUpdateAuthorized(f, user)) { 
        if(foo.getValue() != null) f.setValue(foo.getValue()); 
       } else { 
        throw new UnauthorizedUpdateException(""); 
       } 
      } finally { 
       pm.close(); 
      } 
     } else { 
      throw new OAuthRequestException("Invalid user."); 
     } 

     return foo; 
    } 
} 
+0

È presente questo errore in modo coerente o intermittente? – bossylobster

+0

si verificano costantemente per quasi due giorni. – jrmerz

+0

Ad ogni richiesta a 'gapi.client.myapp.foo.update'? In caso negativo, quale percentuale? – bossylobster

risposta

8

Ho avuto lo stesso problema. Apparentemente non puoi usare "chiave" come campo una volta che ti schieri su GAE. A livello locale ha funzionato bene.

Problemi correlati