2015-05-01 79 views
1

我正在创建一个iOS应用程序,我在其中集成了Office-365-SDK-for-iOS,用于从Outlook365导入联系人。我成功地通过Microsoft Azure进行了身份验证。但是,当我获取用户和用户的联系人,然后下面的错误是coming-集成Office-365-SDK-for-iOS

Error Domain=Error in the Request Code=401 "The operation couldn’t be completed. (Error in the Request error 401.) 

这里是我的验证码,并得到客户

//Acquire access and refresh tokens from Azure AD for the user. 
-(void)acquireAuthTokenWithResourceId:(NSString *)resourceId completionHandler:(void (^)(BOOL authenticated))completionBlock 
{ 
    ADAuthenticationError *error; 
    self.authContext = [ADAuthenticationContext authenticationContextWithAuthority:OutlookAuthority error:&error]; 
    [self.authContext acquireTokenWithResource:OutlookRsourceId 
             clientId:OutlookClientId 
            redirectUri:[NSURL URLWithString:OutlookRedirectUrl] 
           completionBlock:^(ADAuthenticationResult *result) 
    { 
            if (AD_SUCCEEDED != result.status) 
            { 
             completionBlock(NO); 
            } 
            else 
            { 
             NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 
             [userDefaults setObject:result.tokenCacheStoreItem.userInformation.userId 
                 forKey:@"LogInUser"]; 
             [userDefaults synchronize]; 


             self.dependencyResolver = [[ADALDependencyResolver alloc] initWithContext:self.authContext 
                             resourceId:OutlookRsourceId 
                             clientId:OutlookClientId 
                            redirectUri:[NSURL URLWithString:OutlookRedirectUrl]]; 
             completionBlock(YES); 
            } 
           }]; 
} 



- (void) getClient:(void (^) (MSOutlookServicesClient *))callback 
{ 

    OutlookAuthManager* authenticationController = [OutlookAuthManager sharedInstance]; 

    [authenticationController acquireAuthTokenWithResourceId:OutlookRsourceId completionHandler:^(BOOL authenticated) 
    { 

     if (authenticated) 
     { 
      callback([[MSOutlookServicesClient alloc] initWithUrl:@"https://outlook.office365.com/api/v1.0" dependencyResolver:[authenticationController dependencyResolver]]); 
     } 
     else 
     { 
      NSLog(@"Error in authentication"); 
     } 
    }]; 
} 

而且下面我得到用户

[[OutlookAuthManager sharedInstance] getClient:^(MSOutlookServicesClient *client) 
    { 
     NSURLSessionTask* task = [[client getMe] readWithCallback:^(MSOutlookServicesUser *user, NSError *error) 
            { 
             if(error == nil) 
             { 
              dispatch_async(dispatch_get_main_queue(), 
                  ^{ 
                   NSLog(@"------>%@",user.DisplayName); 
                   NSLog(@"------>%@",user.Alias); 
                   NSLog(@"------>%@",user.Id); 
                   NSLog(@"------>%@",user.MailboxGuid); 

                  }); 
             } 
             else 
             { 

              [client.resolver.logger logMessage:error.description withLevel:LOG_LEVEL_ERROR]; 
             } 
            }]; 

     [task resume]; 
    }]; 

但是,这个错误来到这里。 请帮帮我 谢谢

回答

1

validating your access token开始。由于这是一个401,这可能是一个问题。

+0

感谢您的回答。你能否让我知道我将在哪里授予office365在线交流的许可。我没有这种类型的权限。我只有这个类别的Office 365统一API(预览)。 –

+0

Ravi,我在你的其他线索上回答。我的猜测是您的Office 365订阅不包括Exchange Online。您可以使用您的帐户登录到Outlook Web App吗? https://outlook.office365.com –

+0

是的,我有我正在使用的试用订阅。所以这是原因吗? –