Xamarin Android Office 365身份验证
我希望有人能帮助我,我正在尝试创建一个xamarin android应用程序,连接到office 365以获取联系信息。如果你在谷歌上搜索“在你的应用程序中放置一些office 365”并打开第一个链接,就可以找到我下面的教程。作者是Mayur Tendulkar 我能够将连接的服务添加到我的应用程序和所有下载的程序集,尽管教程步骤4的屏幕截图中可见的示例cs文件(ActiveDirectorApiSample、CalendarApiSample等)没有添加到我的项目中: 尝试添加EnsureClientCreated()方法时,visual studio警告我找不到验证器命名空间,因此我尝试添加它:Xamarin Android Office 365身份验证,xamarin,office365,Xamarin,Office365,我希望有人能帮助我,我正在尝试创建一个xamarin android应用程序,连接到office 365以获取联系信息。如果你在谷歌上搜索“在你的应用程序中放置一些office 365”并打开第一个链接,就可以找到我下面的教程。作者是Mayur Tendulkar 我能够将连接的服务添加到我的应用程序和所有下载的程序集,尽管教程步骤4的屏幕截图中可见的示例cs文件(ActiveDirectorApiSample、CalendarApiSample等)没有添加到我的项目中: 尝试添加EnsureC
我注意到visual studio试图使用Xamarin.Auth添加,但如果我检查教程中的源代码,我将遵循Xamarin.Auth参考:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Office365.Exchange;
using Microsoft.Office365.OAuth;
using System.Linq;
namespace O365Client
{
[Activity(Label = "O365 Client", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
GetMessages (this);
}
const string ExchangeResourceId = "https://outlook.office365.com";
const string ExchangeServiceRoot = "https://outlook.office365.com/ews/odata";
public async Task<IEnumerable<IMessage>> GetMessages(Context context)
{
var client = await EnsureClientCreated(context);
var messageResults = await (from i in client.Me.Inbox.Messages
orderby i.DateTimeSent descending
select i).ExecuteAsync();
MyGlobalDeclaration.Messages = messageResults.CurrentPage.ToList ();
ListAdapter = new HomeScreenAdapter(this, MyGlobalDeclaration.Messages);
return messageResults.CurrentPage;
}
private async Task<ExchangeClient> EnsureClientCreated(Context context)
{
Authenticator authenticator = new Authenticator(context);
var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);
return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
}
protected override void OnListItemClick (ListView l, View v, int position, long id)
{
var bodyActivity = new Intent (this, typeof(MessageBodyActivity));
bodyActivity.PutExtra ("Id", v.Tag.ToString());
StartActivity (bodyActivity);
}
}
}
使用系统;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
使用System.Threading.Tasks;
使用System.Collections.Generic;
使用Microsoft.Office365.Exchange;
使用Microsoft.Office365.OAuth;
使用System.Linq;
命名空间O365客户端
{
[活动(Label=“O365客户端”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共类MainActivity:ListActivity
{
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
获取消息(本);
}
常量字符串ExchangeResourceId=”https://outlook.office365.com";
常量字符串ExchangeServiceRoot=”https://outlook.office365.com/ews/odata";
公共异步任务GetMessages(上下文)
{
var client=await EnsureClientCreated(上下文);
var messageResults=wait(来自client.Me.Inbox.Messages中的i)
orderby i.DateTimeSent降序
选择i).ExecuteAsync();
MyGlobalDeclaration.Messages=messageResults.CurrentPage.ToList();
ListAdapter=newhomescreenadapter(这是MyGlobalDeclaration.Messages);
返回messageResults.CurrentPage;
}
专用异步任务EnsureClientCreated(上下文)
{
验证器验证器=新验证器(上下文);
var authInfo=wait authenticator.authenticateSync(ExchangeResourceId);
返回新的ExchangeClient(新的Uri(ExchangeServiceRoot),authInfo.GetAccessToken);
}
受保护的覆盖无效OnListItemClick(列表视图l、视图v、整数位置、长id)
{
var bodyActivity=新意图(此,类型为(MessageBodyActivity));
bodyActivity.PutExtra(“Id”,v.Tag.ToString());
星触觉(身体活动);
}
}
}
如果使用Xamarin.Auth,则visual studio错误为:无法创建抽象类或接口“Xamarin.Auth.Authenticator”的实例
有人能确认我如何解决验证器错误吗 这篇博文似乎是基于Visual Studio工具和Xamarin库的早期版本。请尝试OfficeDev GitHub示例: