Microsoft Graph API:获取文件列表API,给出空数组

时间:2015-11-19 19:26:51

标签: ios objective-c office365 azure-ad-graph-api microsoft-graph

我尝试使用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":[]}

在预先感谢您的帮助:)

我的示例应用的权限 Permissions for my sample app

1 个答案:

答案 0 :(得分:1)

当应用程序无权访问给定用户驱动器根目录中的任何文件时,预计会对该请求作出空响应。您是否可以检查(例如通过http://jwt.calebb.net)您使用的访问令牌是否包含任何Files。*范围? Files.Read足以满足该请求。