我尝试了 API 来获取 iOS SDK 中的文件。
我已经注册了具有所有范围的应用程序以读取/读写文件访问该应用程序。我能够使用示例代码成功发送邮件。
我在 Graph Explorer 中尝试了 API
https://graphexplorer2.azurewebsites.net/?UrlRequest=GET&text=https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%2Fchildren
请求片段:
AuthenticationManager *authManager = [AuthenticationManager sharedInstance];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://graph.microsoft.com/v1.0/me/drive/root/children"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json, text/plain, */*" forHTTPHeaderField:@"Accept"];
NSString *authorization = [NSString stringWithFormat:@"Bearer %@", authManager.accessToken];
[request setValue:authorization forHTTPHeaderField:@"Authorization"];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
NSLog(@"Connection Successful");
} else {
NSLog(@"Connection could not be made");
}
[conn start];
响应:
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('<user-email>')/drive/root/children","value":[]}
提前感谢您的帮助:)
最佳答案
当应用无权访问给定用户驱动器根目录中的任何文件时,预计该请求的响应为空。您可以检查(例如通过 http://jwt.calebb.net )您使用的访问 token 是否有任何 Files.* 范围? Files.Read 足以满足该请求。
关于ios - Microsoft Graph API : Get Files List API, 给出空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33812693/