Created
April 25, 2020 22:17
-
-
Save yuchung-chuang/b66330bf02fac6c07bcfb0519d99b0a4 to your computer and use it in GitHub Desktop.
GraphManager method, to get user information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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