Google Calendar事件API为目标c提供403响应

时间:2018-01-02 18:33:09

标签: ios objective-c google-calendar-api

我使用谷歌日历api终点列出所有日历活动。当我打电话给谷歌日历api时,我得到了403禁止错误响应。我添加了api密钥,在我的云控制台中启用了google calendar api。所以可以帮助我任何人都知道这个问题。

这是我的代码

NSString *calendarId = @"ksmo6aesu64e0pkfr3823ne9d0@group.calendar.google.com";
 NSString *apiKey = @"<My key>";
NSString *urlFormat = @"https://www.googleapis.com/calendar/v3/calendars/%@/events?key=%@";
NSString *calendarUrl = [NSString stringWithFormat:urlFormat, calendarId, apiKey];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", nil];

manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:calendarUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // HTTP request succeeded!
    NSLog(@"Calendar Response Object: %@", responseObject);

    for (NSDictionary *eventData in responseObject[@"items"]) {
        NSLog(@"%@", eventData[@"summary"]);
    }

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

     NSLog(@"%@", error);
    // HTTP request failed!
}];

我的回复是

    Error Domain=   com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={NSLocalizedDescription=Request failed: forbidden (403), NSErrorFailingURLKey=https://www.googleapis.com/calendar/v3/calendars/ksmo6aesu64e0pkfr3823ne9d0@group.calendar.google.com/events?key=AIzaSyDijZIbmwkncoOwNZjg7uzNJD2vx0jrsL8, com.alamofire.serialization.response.error.data=<7b0a2022 6572726f 72223a20 7b0a2020 22657272 6f727322 3a205b0a 2020207b 0a202020 2022646f 6d61696e 223a2022 75736167 654c696d 69747322 2c0a2020 20202272 6561736f 6e223a20 22697052 65666572 6572426c 6f636b65 64222c0a 20202020 226d6573 73616765 223a2022 54686520 63616c6c 696e6720 49502061 64647265 73732031 31312e39 332e3139 362e3135 3420646f 6573206e 6f74206d 61746368 20746865 20495020 72657374 72696374 696f6e73 20636f6e 66696775 72656420 6f6e2074 68652041 5049206b 65792e20 506c6561 73652075 73652074 68652041 50492043 6f6e736f 6c652074 6f207570 64617465 20796f75 72206b65 79207265 73747269 6374696f 6e732e22 2c0a2020 20202265 7874656e 64656448 656c7022 3a202268 74747073 3a2f2f63 6f6e736f 6c652e64 6576656c 6f706572 732e676f 6f676c65 2e636f6d 2f617069 732f6372 6564656e 7469616c 733f7072 6f6a6563 743d3233 39333834 35353734 3633220a 2020207d 0a20205d 2c0a2020 22636f64 65223a20 3430332c 0a202022 6d657373 61676522 3a202254 68652063 616c6c69 6e672049 50206164 64726573 73203131 312e3933 2e313936 2e313534 20646f65 73206e6f 74206d61 74636820 74686520 49502072 65737472 69637469 6f6e7320 636f6e66 69677572 6564206f 6e207468 65204150 49206b65 792e2050 6c656173 65207573 65207468 65204150 4920436f 6e736f6c 6520746f 20757064 61746520 796f7572 206b6579 20726573 74726963 74696f6e 732e220a 207d0a7d 0a>, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x604000421180> { URL: https://www.googleapis.com/calendar/v3/calendars/ksmo6aesu64e0pkfr3823ne9d0@group.calendar.google.com/events?key=AIzaSyDijZIbmwkncoOwNZjg7uzNJD2vx0jrsL8 } { Status Code: 403, Headers {
"Alt-Svc" =     (
    "hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\""
);
"Cache-Control" =     (
    "private, max-age=0"
);
"Content-Encoding" =     (
    gzip
);
"Content-Type" =     (
    "application/json; charset=UTF-8"
);
Date =     (
    "Tue, 02 Jan 2018 18:19:52 GMT"
);
Expires =     (
    "Tue, 02 Jan 2018 18:19:52 GMT"
);
Server =     (
    GSE
);
"Transfer-Encoding" =     (
    Identity
);
Vary =     (
    Origin,
    "X-Origin"
);
"X-Content-Type-Options" =     (
    nosniff
);
"X-Frame-Options" =     (
    SAMEORIGIN
);
"X-XSS-Protection" =     (
    "1; mode=block"
);

}}}

感谢

0 个答案:

没有答案