【问题标题】:Google API "Daily Limit for Unauthenticated use Limit" 403 Error... iOSGoogle API“未经身份验证的使用限制的每日限制”403错误... iOS
【发布时间】:2017-08-13 14:10:48
【问题描述】:

我是 iOS 开发和使用 Google API 的完全初学者。我正在同时学习它们,所以如果这是一个新手问题,我深表歉意。

解析错误已被“废除并替换”为下面的新 API 错误

我正在尝试编写一个应用程序,它会告诉我,在 API 请求时,日历是否在事件中间。

我尝试使用此answer 发布类似的问题。

我的代码现在看起来像这样:(查看底部以获取更新)

let json = "{ \"timeMin\": \(currentDate), \"timeMax\": \(currentDate)}"
urlString = "https://www.googleapis.com/calendar/v3/freeBusy"


let url = URL(string: urlString)!
let jsonData = json.data(using: .utf8, allowLossyConversion: false)!

var request = URLRequest(url: url)
request.httpMethod = HTTPMethod.post.rawValue
request.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData

Alamofire.request(request).responseJSON {
    (response) in
    print (response)
    }

我得到以下输出: (注意:这是通过在 json 参数中指定要从中检索信息的日历来解决的)

SUCCESS: {
    error =     {
        code = 400;
        errors =         (
                        {
                domain = global;
                message = "Parse Error";
                reason = parseError;
            }
        );
        message = "Parse Error";
    };
}

我不确定如何从这里开始 - 另外,发出空闲忙碌的 POST 请求甚至是解决我的问题的最佳方法吗?


更新:

所以我意识到在我的 body 参数中,我没有指定从哪个日历请求信息:我做了以下调整:

    var body : Parameters  = [
    "timeMin": dateString,
    "timeMax": dateString,
    "items": [
        [
            "id": CALENDAR_ID
        ]]
    ]

    Alamofire.request(url, method: HTTPMethod.post, parameters: body, encoding: JSONEncoding.default).responseJSON {
            (response) in
                print(response)
    }
}

但是,现在我收到以下错误:

SUCCESS: {
    error =     {
        code = 403;
        errors =         (
                        {
                domain = usageLimits;
                extendedHelp = "https://code.google.com/apis/console";
                message = "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.";
                reason = dailyLimitExceededUnreg;
            }
        );
        message = "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.";
    };
}

【问题讨论】:

    标签: swift google-api httprequest google-calendar-api alamofire


    【解决方案1】:

    所以我解决了这两个问题:

    首次解析错误

    这个错误,在 freebusy 的上下文中来自我的 POST 参数不是指定从哪些日历检索信息

    解决方案:(关键部分加粗)

    var body : Parameters  = [
        "timeMin": dateString,
        "timeMax": dateString,
        "items": [                //make sure you have this (plus next 4 lines)
            [
               "id": CALENDAR_ID
            ]
        ]
    ]
    

    第二个未经身份验证的使用限制错误

    我在this question 的帮助下解决了这个问题。

    简而言之,所有基于发现的 API 都需要您调用 被识别。你得到的错误是我通常看到的 Google API 无法识别您的应用。你通常可以做一把 来电不明,但您几乎肯定会遇到 非常低的“身份不明”配额很快。你可以 使用 OAuth(标识您的应用程序)进行身份验证,或者您可以指定 一个 API 密钥(用于标识您的应用),或者您可以同时使用两者。

    解决方案

    我通过将 API 密钥附加到我的 URL 解决了这个问题,如下所示(不要点击):

    https://www.googleapis.com/calendar/v3/freeBusy?keys=PASTEKEYHERE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      相关资源
      最近更新 更多