How to get contact list from uwp c#? - c#

How can I get the full contact list from user's phone in UWP?
I have found articles on msdn, but thes use only contact picker that doesn't gives me a full list of the contacts. I just would like to get their names and profile images, noting else.

ContactStore.FindContactsAsync
var contactStore = await ContactManager.RequestStoreAsync();
var contacts = await contactStore.FindContactsAsync();

Related

Get CompanyName for group user using Azure GraphAPI

I am using GraphAPI from Azure and want to GET data from the API using the graphClient SDK. I want to list all members of a specific group and display some more details about them. The problem is that I miss the property CompanyName in the response from the API (null).
I build the request like this (searchParam is the group id):
await graphClient.Groups[searchParam.ToString()]
.Members
.Request()
.GetAsync(cancellationToken);
Anyone know if I can get the CompanyName in the same request? (I dont want to make another request just to fetch the companyname).
I tried filter and extend methods, but not sure if that is the way to go?
Thanks for your time and help!
try this code pls and it worked for me.
var members = await graphClient.Groups["{group_id}"].Members.Request().Select("id,displayName,companyName").GetAsync();
This is because, when we call list member graph api, it will return a list of directoryObject objects, and user is also a kind of directoryObject. And when user is the response, it won't return companyName by default, so we need to use Odata select feature.

Problem fetching contact container Xamarin.iOS

I got a problem with a little application I'm developing using Xamarin.iOS
My goal is simply to get every contacts present on an iPhone.
I have this code, it worked until now on my phone and at least 3 others.
Yesterday I added someone in my provisioning profile, since, I can't get any other value than 'null' on my phone when I try to fetch a container.
My phone is an iPhone 7 iOS 13.1.2 - I can't test it on any other phone until a little moment.
It still works on a simulator (iPhone 8 iOS 13.1).
I have the contact authorization request in my info.plist.
I just don't understand what getting 'null' means when fetching a default container ...
try
{
var keysTOFetch = new[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.Nickname, CNContactKey.JobTitle, CNContactKey.DepartmentName, CNContactKey.OrganizationName, CNContactKey.PostalAddresses, CNContactKey.UrlAddresses, CNContactKey.EmailAddresses, CNContactKey.PhoneNumbers };
NSError error;
CNContact[] contactList;
var ContainerId = new CNContactStore().DefaultContainerIdentifier; <---- //This where I get a null I never got before ...
if (ContainerId != null)
{
using (var predicate = CNContact.GetPredicateForContactsInContainer(ContainerId))
using (var store = new CNContactStore())
contactList = store.GetUnifiedContacts(predicate, keysTOFetch, out error);
var contacts = new List<UserContact>();
status = writeCSV(contactList, user);
}
else
Console.WriteLine("Didn't get any container identifier ..");
}
Apple documentation says it can return 'null' but without further explanation ..
Thanks a lot for your help
You are facing this issue on some phones and not other because the phone that work have only one container that it is trying load contacts from, while the phones that don't work have more than one container (i.e. Gmail, Exchange, iCloud accounts used to store contacts). So you are only loading the contacts from the account that is configured as the default, which has 0 contacts. Therefore, it would not load all contacts as requested.
Solution: Get all the containers and iterate over them to extract all contacts from each of them. You might be able to find some samples of it on Github.

Retrieve all mobile devices Google Directory API in .NET Application

I want to Manage Device using Google API in my appilcation.How to retrieve all mobile/chrome OS device ?
CODE :
var listReq1 = service.Mobiledevices.List(serviceAccountEmail);
MobileDevices allUsers = listReq1.Execute();
Here,
serviceAccountEmail = "Service accounts Key" (Console.developer.google.com)
I am getting error like
Google.Apis.Requests.RequestError
Bad Request [400]
I tried using
var listReq= new Google.Apis.Admin.Directory.directory_v1.MobiledevicesResource.ListRequest(service,serviceAccountEmail);
Still not working ? I want all details of User just like Below Image
If you check the documentation for Mobiledevices: list
Retrieves a paginated list of all mobile devices for an account.
I will see that it takes a customer id as a parmater.
customerId The unique ID for the customer's Google account. As
an account administrator, you can also use the my_customer alias to
represent your account's customerId. The customerId is also returned
as part of the Users resource.
var listReq1 = service.Mobiledevices.List(customerId);
MobileDevices allUsers = listReq1.Execute();
You are sending service account email address which I really don't think is your customer id.

Adding contacts to People on Windows Phone 8.1 in C#

Is there a way to add contacts from my app to the People app on a Windows Phone 8.1? I looked at different things under the Contact class and nothing seems to work. There are different ways (like ContactManager, ContactPicket, etc.) to retrieve data but nothing seems to allow me to add a new contact as most of the stuff like SaveContactTask in Microsoft.Phone.Tasks is not implemented on WP 8.1.
J.
You don't have write access to the primary contact store on Windows Phone 8, but you have the ability to create your own contact store for the app which you can use to manage contacts created in your own app.
The mechanism is pretty simple:
using Windows.Phone.PersonalInformation;
public async void addPerson() {
var store = await ContactStore.CreateOrOpenAsync();
var contact = new StoredContact(store) {
DisplayName = "Mike Peterson"
};
var props = await contact.GetPropertiesAsync();
props.add(KnownContactProperties.Email, "mike#peterson.com");
props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");
await contact.SaveAsync();
}
To inform the OS that you provide contact information, you need to add the ID_CAP_CONTACTS/Contacts capability to your app (in the Capabilities section of the appxmanifest). Contacts remain until the app is removed.
Private, owned by the app contacts are convenient for 'contact' data for the app.

Using "ContactsQuery" for searching particular contact in Google contact using Google API Ver 2

Currently i am searching particular as below:
Feed<Contact> f = contactsRequest.GetContacts();
foreach (Contact e in f.Entries)
{
if (e.Title == "MyContact")
{
MesageBox.Show("Contact already exist");
}
}
This will work fine if no of contacts are less.But above code will become slow for large no of contacts.
I read about "ContactsQuery".How can i use it for above scenario ?
There is no support for full-text queries or locating a contact by email address
If you want to find a particular contact, you have to retrieve all contacts then search for the contact yourself, there's no other way at the moment.
ContactsQuery allow you to filter by:
NumberToRetrieve
StartIndex
StartDate
ShowDeleted
OrderBy
last-modifieddate
SortOrder
Group
and other parameters defined in:
Contact Data API reference
Google Data API refence
Google.GData.Contacts namespace

Categories