0
votes

I hope someone can help me, I am trying to create a xamarin android app that connects to office 365 to pull contact information. the tutorial I am following can be found if you google "put some office 365 in your apps" and open the first link. Author is Mayur Tendulkar.

I am able to add the connected service to my application and all the assemblies download although the sample cs files visible in the screenshot for step 4 from the tutorial(ActiveDirectorApiSample, CalendarApiSample etc) do not get added into my project: http://i.imgur.com/olLfjoN.png

When trying to add the EnsureClientCreated() method visual studio warns me that the Authenticator namespace could not be found so I try and add it :
http://i.imgur.com/JSRc3ha.png

I noticed that visual studio tries to add using Xamarin.Auth but if I check the source code from the tutorial I am following the Xamarin.Auth reference is not there:

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

If I use Xamarin.Auth then visual studio errors with: Cannot create an instance of the abstract class or interface "Xamarin.Auth.Authenticator"

can anyone confirm how I can resolve the Authenticator errors?

1

1 Answers

0
votes

It looks like that blog post is based on an earlier version of the Visual Studio tools and Xamarin libraries. Try the OfficeDev GitHub sample: https://github.com/OfficeDev/XamarinAndroidO365.