代码之家  ›  专栏  ›  技术社区  ›  Bernd Schiffer

DailyLimitExceedDunReg:超出未经验证使用的每日限制。继续使用需要注册

  •  0
  • Bernd Schiffer  · 技术社区  · 7 年前

    当我第二次执行脚本时,我得到错误

    dailyLimitExceededUnreg: Daily Limit for Unauthenticated Use Exceeded.
    Continued use requires signup. (Google::Apis::ClientError)
    

    require 'google/apis/drive_v3'
    require 'googleauth'
    require 'googleauth/stores/file_token_store'
    require 'fileutils'
    
    OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
    APPLICATION_NAME = 'Maker'.freeze
    CREDENTIALS_PATH = 'credentials.json'.freeze
    
    FILE_ID = '<my-file-id>'
    
    # The file token.yaml stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    #
    # copied from https://developers.google.com/drive/api/v3/quickstart/ruby
    TOKEN_PATH = 'token.yaml'.freeze
    SCOPE = Google::Apis::DriveV3::AUTH_DRIVE
    
    ##
    # Ensure valid credentials, either by restoring from the saved credentials
    # files or initiating an OAuth2 authorization. If authorization is required,
    # the user's default browser will be launched to approve the request.
    #
    # @return [Google::Auth::UserRefreshCredentials] OAuth2 credentials
    #
    # copied from https://developers.google.com/drive/api/v3/quickstart/ruby
    def authorize
      client_id = Google::Auth::ClientId.from_file CREDENTIALS_PATH
      token_store = Google::Auth::Stores::FileTokenStore.new file: TOKEN_PATH
      authorizer = Google::Auth::UserAuthorizer.new client_id, SCOPE, token_store
      user_id = 'default'
      credentials = authorizer.get_credentials user_id
      create_credentials(authorizer, user_id) if credentials.nil?
    end
    
    def create_credentials(authorizer, user_id)
      url = authorizer.get_authorization_url base_url: OOB_URI
      puts 'Open the following URL in the browser and enter the ' \
             "resulting code after authorization:\n" + url
      code = STDIN.gets
      authorizer.get_and_store_credentials_from_code user_id: user_id,
                                                     code: code,
                                                     base_url: OOB_URI
    end
    
    # copied from https://developers.google.com/drive/api/v3/about-auth
    def download_csv
      service = Google::Apis::DriveV3::DriveService.new
      service.client_options.application_name = APPLICATION_NAME
      service.authorization = authorize
      service.export_file(FILE_ID, 'text/csv') #only downloading first sheet
    end
    
    puts download_csv
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Bernd Schiffer    7 年前

    谷歌的快速启动示例( https://developers.google.com/drive/api/v3/quickstart/ruby )引用了他们的API版本0.8,该版本已过时。有一个更新的版本0.11。当我安装的时候,一切都完美无瑕。

    推荐文章