我是iOS开发人员和使用谷歌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";
    };
}

我不确定如何从这里开始-而且,是否提出一个忙得不可开交的帖子请求,甚至是解决我的问题的最佳方法?
更新:
因此,我认识到在我的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.";
    };
}

最佳答案

所以我发现了两个问题:
第一-分析错误
在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都需要调用
被识别。你得到的错误是我通常看到的
谷歌API无法识别你的应用程序。你通常可以做一把
但你肯定会遇到
很快就降低了“未确认”的配额。你也可以
使用OAuth(标识您的应用程序)进行身份验证,或者您可以指定
API密钥(用于标识应用程序)或两者都可以。
解决方案
我通过将API密钥附加到我的URL来解决这个问题,如下所示(不要单击):
https://www.googleapis.com/calendar/v3/freeBusy?keys=pastekeyhere

10-07 19:23
查看更多