【发布时间】: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