Ho un'API Endpoint distribuita su App Engine. Non ho problemi a utilizzare Google API Explorer per effettuare richieste ai metodi API che NON richiedono l'accesso. L'URL che sto utilizzando è:Come utilizzare Google API Explorer per testare i miei endpoint di App Engine utilizzando OAuth?
https://developers.google.com/apis-explorer /?base=https://[MY_APP_ID].appspot.com/_ah/api
Dove sono bloccato sta chiamando metodi API che richiedono all'utente di effettuare il login, come questa:
@ApiMethod(name = "config.get",
clientIds = {"[MY_CLIENT_ID].apps.googleusercontent.com", "com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID"},
audiences = {"[MY_APP_ID].appspot.com"},
scopes = {"https://www.googleapis.com/auth/userinfo.email"})
public Config getConfig(User user) throws OAuthRequestException {
log.fine("user: " + user);
if (user == null) {
throw new OAuthRequestException("You must be logged in in order to get config.");
}
if (!userService.isUserAdmin()) {
throw new OAuthRequestException("You must be an App Engine admin in order to get config.");
}
...
Nell'API Explorer c'è un interruttore in alto a destra che, quando si fa clic, mi consente di specificare gli ambiti e autorizzare. Lo faccio solo con l'ambito userinfo.email controllato. Non fa differenza. La risposta che ricevo da mia chiamata è:
503 Service Unavailable
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "java.lang.IllegalStateException: The current user is not logged in."
}
],
"code": 503,
"message": "java.lang.IllegalStateException: The current user is not logged in."
}
}
Ai tempi in cui endpoint era in fase di Trusted Tester, mi ricordo che ci sia un passo manuale nel OAuth2 Playground per ottenere un ID di token invece di un token di accesso o qualcosa del genere . Se ciò è ancora necessario, qualsiasi menzione di ciò sembra essere scomparsa dai documenti di Endpoints ora e ora vedo anche il modo per scambiare i token nell'API Explorer.
Oh, e ho anche aggiunto il campo giochi OAuth (https://developers.google.com/oauthplayground) all'elenco di URI di reindirizzamento nella console API. – Eliot