0

グーグルクラウドストレージにグーグルドキュメントを保存したい。私は管理者ユーザーであり、Googleクラウドストレージにアクセスできます。私はこのコードを使用しています:

 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サーバーエラーが発生します。どんな提案も私に役立つでしょう。

この問題は解決されました。コードを修正して更新しました。

4

3 に答える 3

0

Google Cloud Storage のドキュメントには、OAuth 1.0 を使用する場合は API キーも渡す必要があると記載されています。

https://developers.google.com/storage/docs/json_api/v1/how-tos/authorizing

于 2012-10-19T20:17:33.417 に答える