【问题标题】:Ruby on rails: Google API dailyLimitExceededUnregRuby on rails:Google API dailyLimitExceededUnreg
【发布时间】:2018-10-08 02:46:00
【问题描述】:

大家好,我从 google 获取一些令牌时出错。您对此错误有任何想法吗?并告诉我如何解决这个错误。

[{"domain"=>"usageLimits", "reason"=>"dailyLimitExceededUnreg", "message"=>"已超过未经验证使用的每日限制。继续使用需要注册。", "extendedHelp"=>"@ 987654321@"}], "code"=>403, "message"=>"已超过每日未经身份验证使用限制。继续使用需要注册。"}}

我的获取代码:

    def self.request_tokens(code)
      Request.post('https://www.googleapis.com/oauth2/v4/token', {
        client_id: 'XXXXXXXXXXXXXX',
        client_secret: 'XXXXXXXXXXXXXX',
        redirect_uri: 'http://localhost:8080',
        grant_type: 'authorization_code',
        code: code,
      })
    end

    def self.request_profile(access_token)
      Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}")[:body]
    end

添加:

我已经添加了这样的 API 密钥。

      def self.request_profile(access_token)

      # Add api key but failed
        Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}?key=XXXXXXXXXXXXX")[:body]

      # try like this but failed
        plus = Google::Apis::PlusV1::PlusService.new
        plus.key = 'XXXXXXXXXXXXX'
        plus.authorization = access_token

      end

【问题讨论】:

    标签: google-api google-oauth


    【解决方案1】:

    这正是它所说的意思。您过度使用 Google 的 API,因此除非您注册 API 密钥,否则他们不会让您在一天的剩余时间内使用它。 https://code.google.com/apis/console,你错误中的链接,会让你这样做。

    【讨论】:

    • 谢谢 Joseph,我如何注册 Google 的 API?
    • 仅供参考此错误消息不是超出配额的错误消息。这是不向请求消息添加任何身份验证。
    【解决方案2】:

    "未经身份验证的使用已超过每日限制。继续使用需要注册。",

    表示您尝试在未经过身份验证或使用 api 密钥(使用有效客户端)的情况下访问 Google api。为了访问所有 google api,您必须在 Google 开发者控制台上创建一个项目。如果您要访问公共数据,则可以使用 api 密钥;如果您要访问私有用户数据,则需要使用 Oauth2。

    您似乎已尝试在代码中设置客户端 ID。问题是它没有正确应用于您的请求。我不是 ruby​​ 开发人员,因此无法帮助您调试代码,尽管 google 有许多 ruby​​ 教程OAuth 2.0

    还有use api key

    require 'google/apis/plus_v1'
    
    plus = Google::Apis::PlusV1::PlusService.new
    plus.key = 'api_key'
    

    【讨论】:

    • 非常感谢您的友好回复,我会尽力做到的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 2020-05-02
    • 2016-07-24
    • 2017-06-16
    • 2017-01-16
    相关资源
    最近更新 更多