gpt4 book ai didi

ios - 集成 Office-365-SDK-for-iOS

转载 作者:行者123 更新时间:2023-11-29 12:23:13 24 4
gpt4 key购买 nike

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

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];
}];

但是这个错误就在这里。请帮我谢谢

最佳答案

开始于validating your access token 。由于它是 401,因此可能存在问题。

关于ios - 集成 Office-365-SDK-for-iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29985214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com