我想将谷歌文档存储在谷歌云存储上。我是管理员用户,可以访问谷歌云存储。我使用这段代码:
function myFunction() {
var base="https://www.googleapis.com/auth/devstorage.full_control"
var fetchArgs=googleOAuth_('provisioning',base)
fetchArgs.payload=<content_data_that you want to put on GCS>
fetchArgs.method='PUT'
fetchArgs. contentType=<content_type>
fetchArgs.host="<bucket_name>.storage.googleapis.com"
var url='https://storage.googleapis.com/<bucket_name>/<file_name>'
var result=UrlFetchApp.fetch(url,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"};
}
当我运行此代码时,它会给出 503 服务器错误。任何建议都会对我有所帮助。
这个问题已经解决了。用更正更新了代码。