Reputation: 139
I am not able to get the Google Calendar framework to compile in my iOS project, so I decided to build the requests manually after getting my Oauth token from Google SignIn's framework.
I have been running into a wall for the past day. The following doesn't seem to want to provide me access, I keep getting a 403 error.
func requestEvents() {
let email = GIDSignIn.sharedInstance().currentUser.profile.email.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
let token = GIDSignIn.sharedInstance().currentUser.authentication.accessToken
let urlString = "https://www.googleapis.com/calendar/v3/calendars/\(email!)/events?key=CalendarHelper.apiKey
let url = NSURL(urlString)
let request = NSMutableURLRequest(URL: url)
request.addValue("Bearer \(token!)", forHTTPHeaderField: "authorization")
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request) { data, request, error in
print(NSJSONSerialization.jsonobjectwithdata(data, options: .PrettyPrinted))
}
Upvotes: 1
Views: 992
Reputation: 139
After spending an entire day trying to figure this out I finally found the answer.
I used the Google API explorer to make a request for my own calendar information and then inspected the header sent with that request. In the Google generated request the auth header looks like this:
authroziation : "Bearer [tokenString]"
After I was able to get out from under my deadline I found this page in the Oauth specification.
https://www.rfc-editor.org/rfc/rfc6750#section-2
Upvotes: 2