Giter VIP home page Giter VIP logo

Comments (7)

erickoledadevrel avatar erickoledadevrel commented on May 29, 2024

Unfortunately the length of the callback URL cannot be changed, as the state token is needed in order to route the callback correctly. I'll talk with the Apps Script engineering team to see if there is any way we can compress the state tokens more.

from apps-script-oauth1.

simonbromberg avatar simonbromberg commented on May 29, 2024

So my code is ok? Is Fitbit providing the callback URL?

from apps-script-oauth1.

erickoledadevrel avatar erickoledadevrel commented on May 29, 2024

Your code is fine. This library is creating the callback URL, but unfortunately there is currently no way to make it smaller but still have work in Apps Script.

from apps-script-oauth1.

erickoledadevrel avatar erickoledadevrel commented on May 29, 2024

Note that FitBit just released OAuth2 support:

https://community.fitbit.com/t5/Web-API/OAuth-2-0-beta-is-here/m-p/778224#U778224

The OAuth2 library has been updated to support it:

https://goo.gl/EcddOz

Here's some sample code that shows how to make to use that library with it:

function fitbitTest() {
  var service = getFitbitService();
  if (service.hasAccess()) {
    var date = new Date();
    date.setDate(date.getDate() - 1);
    var dateStr = Utilities.formatDate(date, Session.getScriptTimeZone(), 'yyyy-MM-dd');
    var url = 'https://api.fitbit.com/1/user/-/activities/date/' + dateStr + '.json';
    var response = UrlFetchApp.fetch(url, {
      headers: {
        'Authorization': 'Bearer ' + service.getAccessToken()
      }
    });
    Logger.log(JSON.stringify(JSON.parse(response.getContentText()), null, 2));
  } else {
    var authUrl = service.getAuthorizationUrl();
    Logger.log('Visit this url: ' + authUrl);
  }
}

function getFitbitService() {
  var clientId = '...';
  var clientSecret = '...';
  return OAuth2.createService('fitbit')
      .setAuthorizationBaseUrl('https://www.fitbit.com/oauth2/authorize')
      .setTokenUrl('https://api.fitbit.com/oauth2/token')
      .setClientId(clientId)
      .setClientSecret(clientSecret)
      .setProjectKey('...')
      .setCallbackFunction('fitbitAuthCallback')
      .setPropertyStore(PropertiesService.getUserProperties())
      .setScope('activity')
      .setTokenHeaders({
        'Authorization': 'Basic ' + Utilities.base64Encode(clientId + ':' + clientSecret)
      });
}

function fitbitAuthCallback(request) {
  try {
    var service = getFitbitService();
    var authorized = service.handleCallback(request);
    if (authorized) {
      return HtmlService.createHtmlOutput('Success! You can close this tab.');
    } else {
      return HtmlService.createHtmlOutput('Denied. You can close this tab');
    }
  } catch (e) {
    return HtmlService.createHtmlOutput('Error: ' + e);
  }
}

I'll leave this issue open however, since they may be other APIs that run into the URL length issue.

from apps-script-oauth1.

simonbromberg avatar simonbromberg commented on May 29, 2024

Thanks

It actually started working again a day or two later, so not really sure what the problem was.

from apps-script-oauth1.

GGPay avatar GGPay commented on May 29, 2024

Hi Eric,
Thanks for library.
Has this issue been resolved? I have the same error trying to use for Etsy.

from apps-script-oauth1.

erickoledadevrel avatar erickoledadevrel commented on May 29, 2024

A work around we can use for APIs that only support 255 character callback URLs is to publish the script as a web app, and use that URL instead of the /usercallback URL. I published an Etsy sample that does that:

https://github.com/googlesamples/apps-script-oauth1/blob/master/samples/Etsy.gs

from apps-script-oauth1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.