Comments (7)
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.
So my code is ok? Is Fitbit providing the callback URL?
from apps-script-oauth1.
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.
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:
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.
Thanks
It actually started working again a day or two later, so not really sure what the problem was.
from apps-script-oauth1.
Hi Eric,
Thanks for library.
Has this issue been resolved? I have the same error trying to use for Etsy.
from apps-script-oauth1.
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)
- QuickBooks error when querying with = HOT 1
- Modify Callback Function? HOT 2
- Not working anymore? HOT 1
- Lack of RSA-SHA1 support HOT 3
- Support for "2-legged" OAuth v1.0a? HOT 6
- Goodreads OAuth Problems HOT 3
- Support for Standalone Google Apps Script Projects HOT 1
- Etsy OAuth 1.0 issues HOT 9
- OAUTH Token undefined HOT 2
- OAuth1a without TokenUrl HOT 5
- Can I pass Basic Auth of request url ? HOT 4
- Unknown or previously rejected token HOT 1
- XeroPrivate.gs needs PLAINTEXT oauth signature method but RSA-SHA1 encoded consumer secret HOT 1
- Upgrade to the latest version of the OAuth signer library
- Implement fetchAll
- OAuth1 not working in Chrome V8 Engine HOT 1
- Trello Invalid Signature HOT 1
- Security: OAuth Client ID and Secret are accessible to any user of an Apps Script in almost all samples HOT 1
- [SyncRepoSettings bot] - Invalid config file
- .
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apps-script-oauth1.