【问题标题】:Upload a file into drive using google apss script使用谷歌应用脚​​本将文件上传到驱动器
【发布时间】:2012-12-12 07:54:32
【问题描述】:

我正在尝试将图像文件上传到谷歌驱动器... 代码;

function upload() {
  var url= // url for image
  var contents=UrlFetchApp.fetch(url).getContent()   // trying to get image content
  var base = 'https://docs.google.com/feeds' 
  var fetchArgs = googleOAuth_('docs', base);
  fetchArgs.method='POST'
  fetchArgs.contentType='image/jpeg'
  var xml={title :"image",content:contents}
  fetchArgs.payload=xml
  var fileURL='https://www.googleapis.com/upload/drive/v2/files?uploadType=media'
  UrlFetchApp.fetch(fileURL, fetchArgs)
}

function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setConsumerKey(consumerKey);
  oAuthConfig.setConsumerSecret(consumerSecret);
  return {oAuthServiceName:name, oAuthUseToken:"always"};
}

当我运行这段代码时,我收到了这个错误:

返回代码 403 的请求失败。服务器响应:{“error”:{“errors”:[{“domain”:“usageLimits”,“reason”:“dailyLimitExceededUnreg”,“message”:“未验证的每日限制使用已超过。继续使用需要注册。", "extendedHelp": "https://code.google.com/apis/console" } ], "code": 403, "message": "每日未验证使用限制已超过。继续使用需要注册。" } }

我做错了什么,我没有得到这个......请给我一些可行的解决方案

【问题讨论】:

    标签: google-apps-script google-drive-api


    【解决方案1】:

    这是怎么回事:

    DocsList.createFile(UrlFetchApp.fetch(fileURL, fetchArgs));
    

    作为整个代码的替代品?

    【讨论】:

    • 如果我想将文件从用户帐户上传到管理员帐户的驱动器,那么你的一行代码将不起作用.....然后我必须使用我上面的代码,但它正在创建错误。 ...那有什么解决办法????
    • 如果您收到上述错误,请阅读它所说的内容...您超出了某些配额限制。该错误来自驱动器 api,而不是来自应用程序脚本;您必须查看该文档以获取帮助。
    • 但是我只运行了一次上面的代码,我得到了这个错误。。一次运行,我得到配额限制错误,有点混乱......:(
    • 1) 仍然不是 Apps 脚本问题 - 您需要询问了解 Drive api 的人。 2)也许配额是0没有注册?这就是我对消息的解释。
    猜你喜欢
    • 2020-03-13
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多