Skip to content

Instantly share code, notes, and snippets.

@yuchung-chuang
Created April 25, 2020 22:17
Show Gist options
  • Save yuchung-chuang/b66330bf02fac6c07bcfb0519d99b0a4 to your computer and use it in GitHub Desktop.
Save yuchung-chuang/b66330bf02fac6c07bcfb0519d99b0a4 to your computer and use it in GitHub Desktop.
GraphManager method, to get user information
public func getMe(completion: @escaping(MSGraphUser?, Error?) -> Void) {
let meRequest = NSMutableURLRequest(url: URL(string: "\(MSGraphBaseURL)/me")!)
let meDataTask = MSURLSessionDataTask(request: meRequest, client: self.client, completion: {
(data: Data?, response: URLResponse?, graphError: Error?) in
guard let meData = data, graphError == nil else {
completion(nil, graphError)
return
}
do {
// Deserialize response as a user
let user = try MSGraphUser(data: meData)
completion(user, nil)
} catch {
completion(nil, error)
}
})
// Execute the request
meDataTask?.execute()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment