2012-04-26 5 views
8

He intentado utilizar oAuth en Google apps script para acceder a los datos de trello, pero parece que la API de OAuthService hace algunas suposiciones sobre el servicio de OAuth y que trello no funciona de esa manera.Script de aplicaciones de Google oauth connect no funciona con trello

El siguiente código funciona. Es el acceso a Twitter de conseguir (esto es de tutorial oauth de Google):

function authorizeToTwitter() { 
    var oauthConfig = UrlFetchApp.addOAuthService("twitter"); 
    oauthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token"); 
    oauthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token"); 
    oauthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize"); 
    oauthConfig.setConsumerKey(<CONSUMER KEY>); 
    oauthConfig.setConsumerSecret(<CONSUMER SECRET>); 
    var requestData = { 
    "method": "GET", 
    "oAuthServiceName": "twitter", 
    "oAuthUseToken": "always" 
    }; 
    var result = UrlFetchApp.fetch("https://api.twitter.com/1/statuses/mentions.json", requestData); 
} 

El siguiente código me va a llegar al Trello "pulse OK para volver" página, pero Trello no sabe cómo redirigir hacia atrás, así que llegar a una página que le pide que copie manualmente pegar un token (Google, pero no me proporciona con un método de inserción de esa señal)

function authorizeToTrello() { 
    var oauthConfig = UrlFetchApp.addOAuthService("trello"); 
    oauthConfig.setAccessTokenUrl("https://trello.com/1/OAuthGetAccessToken"); 
    oauthConfig.setRequestTokenUrl("https://trello.com/1/OAuthGetRequestToken"); 
    oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken"); 
    oauthConfig.setConsumerKey(<CONSUMER KEY>); 
    oauthConfig.setConsumerSecret(<CONSUMER SECRET>); 
    var requestData = { 
    "method": "GET", 
    "oAuthServiceName": "trello", 
    "oAuthUseToken": "always" 
    }; 
    var result = UrlFetchApp.fetch(
     "https://api.trello.com/1/members/me/boards", 
     requestData); 
} 

traté de arreglar esto añadiendo manualmente la devolución de llamada redirección que Proporciono a twitter en el url de autorización

oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?return_url=https://docs.google.com/macros"); //this is what the tutorial says I should provide to twitter 

o

oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?return_url=https://docs.google.com/macros/externaloauthcallback"); //this is what twitter actually calls when performing the oauth dance 

Pero ambos no funcionan. ¿Estoy haciendo algo mal? ¿Me faltan algunos parámetros de configuración que debería proporcionar?

+0

El error que hacía que este problema se ha solucionado. –

Respuesta

10

Este comportamiento se debe a a bug in the Trello API; Google intenta proporcionar un oauth_callback cuando obtiene su token de autorización, pero Trello no redireccionó allí cuando usted aprueba la solicitud del token.

Este error ya se ha resuelto, y he verificado que el código siguiente funciona:

function authorizeToTrello() { 
  var oauthConfig = UrlFetchApp.addOAuthService("trello"); 
  oauthConfig.setAccessTokenUrl("https://trello.com/1/OAuthGetAccessToken"); 
  oauthConfig.setRequestTokenUrl("https://trello.com/1/OAuthGetRequestToken"); 
  oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken"); 

    // Replace these with the values you get from 
    // https://trello.com/1/appKey/generate 
  oauthConfig.setConsumerKey("Consumer Key"); 
  oauthConfig.setConsumerSecret("Consumer Secret"); 

  var requestData = { 
    "method": "GET", 
    "oAuthServiceName": "trello", 
    "oAuthUseToken": "always" 
  }; 

  var result = UrlFetchApp.fetch(
      "https://api.trello.com/1/members/me/boards", 
      requestData); 

  Logger.log(result.getContentText()); 
} 
+0

¡Gracias! ¡Tanto por la respuesta como (supongo) para solucionar el error! – Jauco

+1

Sí, lo he verificado también. – Jauco

Cuestiones relacionadas