Connect a google app script to dropbox
i want to be able to send files from drive to dropbox, but i'm having some issues. I get a message to enter into the authorization url:
Please visit the following URL and then re-run the script: https://www.dropbox.com/1/oauth/authorize?oauth_token=xxxxxxx
I do, the app is added to dropbox (or at least i get a message saying that), but if i re-run the script, i get the same message again. And if i check the list of apps connected to dropbox, this one does not appear... I tried to follow this:Migrating from OAuthConfig to the OAuth1 library as close as possible... What i'm doing wrong?
function Gmail2Dropbox() {
var service = getDropboxService();
if (service.hasAccess()){
var folderName = "foldername";
var folder = DriveApp.getFoldersByName(folderName).next();
var files = folder.getFiles();
while (files.hasNext()){
var file = files.next();
var fileName = file.getName();
Logger.log(fileName);
var options = {
"oAuthServiceName" : "dropbox",
"oAuthUseToken" : "always",
"method" : "put",
"payload" : file.getBlob().getBytes(),
"contentType" : file.getMimeType()
};
var response = UrlFetchApp.fetch("https://api-content.dropbox.com/1/files_put/sandbox/" + folderName + "/" + fileName, options);
Logger.log(response);
}
}
else {
var authorizationUrl = service.authorize();
Logger.log('Please visit the following URL and then re-run the script: ' + authorizationUrl);
}
}
function getDropboxService() {
var dropboxKey = "dropKey";
var dropboxSecret = "dropSecret";
var service = OAuth1.createService('dropbox');
service.setRequestTokenUrl("https://api.dropbox.com/1/oauth/request_token");
service.setAuthorizationUrl("https://www.dropbox.com/1/oauth/authorize");
service.setAccessTokenUrl("https://api.dropbox.com/1/oauth/access_token");
service.setConsumerKey(dropboxKey);
service.setConsumerSecret(dropboxSecret);
service.setCallbackFunction('authCallback');
service.setPropertyStore(PropertiesService.getScriptProperties());
return service;
}
function authCallback(request) {
var service = getDropboxService;
var isAuthorized = service.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this page.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this page');
}
}
Check out IFTTT they have a channle called Maker Channel. IFTTT connects hundreds of services together, making it easy to connect between services. With this you do not need OAuth, and it is much easier to use. They do not have direct support from Drive to Dropbox, so you must use their Maker Channel, which is an API. Once you set up an applet Maker Channel to Dropbox you can upload a file via a POST api call to the Maker Channel. It is very easy to use and I have made a function for it.
function sendToMaker(makerKey,eventName,value1,value2,value3){
var url = 'https://maker.ifttt.com/trigger/' + eventName + '/with/key/' + makerKey;
var payload = {
'value1' : value1,
'value2' : value2,
'value3' : value3
};
var options = {
'method' : 'POST',
'payload':payload,
};
return UrlFetchApp.fetch(url,options);
};
When you set up the applet on IFTTT when it comes to the Dropbox side, you will need to map File URL, Name, and destination. I map File URL to the "Value1", name to "Value2," and destination "Value3." Remember to format destination properly, just look at the example IFTTT has.
Once the applet is set up, you can then send your files form Drive to Dropbox.
链接地址: http://www.djcxy.com/p/69084.html上一篇: 使用谷歌应用程序脚本将文件从谷歌驱动器发送到Dropbox
下一篇: 将谷歌应用程序脚本连接到保管箱