如何从IOneDriveClient
获取用户名或电子邮件?如何从onedriveclient sdk获取用户名或电子邮件c#
认证:
string[] scopes = { "onedrive.readwrite" };
IOneDriveClient OneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes);
await OneDriveClient.AuthenticateAsync();
如何从IOneDriveClient
获取用户名或电子邮件?如何从onedriveclient sdk获取用户名或电子邮件c#
认证:
string[] scopes = { "onedrive.readwrite" };
IOneDriveClient OneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes);
await OneDriveClient.AuthenticateAsync();
我们不能从IOneDriveClient
直接获取用户名或电子邮件。但形式IOneDriveClient
我们可以得到AccessToken
。当我们有AccessToken
时,我们可以将它与Live Connect具象状态传输(REST)API一起使用来检索用户的名称。
GET https://apis.live.net/v5.0/me?access_token=ACCESS_TOKEN
欲了解更多资讯,请Requesting info using REST:
的REST API来对登录的用户请求信息。
所以在应用中,我们可以使用下面的代码来获取用户的显示名称:
string[] scopes = new string[] { "onedrive.readwrite" };
var client = OneDriveClientExtensions.GetUniversalClient(scopes) as OneDriveClient;
await client.AuthenticateAsync();
//get the access_token
var AccessToken = client.AuthenticationProvider.CurrentAccountSession.AccessToken;
//REST API to request info about the signed-in user
var uri = new Uri($"https://apis.live.net/v5.0/me?access_token={AccessToken}");
var httpClient = new System.Net.Http.HttpClient();
var result = await httpClient.GetAsync(uri);
//user info returnd as JSON
string jsonUserInfo = await result.Content.ReadAsStringAsync();
if (jsonUserInfo != null)
{
var json = Newtonsoft.Json.Linq.JObject.Parse(jsonUserInfo);
string username = json["name"].ToString();
}
要获得用户的电子邮件,我们需要在scopes
添加wl.emails
范围。 wl.emails scope可以读取用户的电子邮件地址。的代码可能会喜欢以下:
string[] scopes = new string[] { "onedrive.readwrite", "wl.emails" };
var client = OneDriveClientExtensions.GetUniversalClient(scopes) as OneDriveClient;
await client.AuthenticateAsync();
//get the access_token
var AccessToken = client.AuthenticationProvider.CurrentAccountSession.AccessToken;
//REST API to request info about the signed-in user
var uri = new Uri($"https://apis.live.net/v5.0/me?access_token={AccessToken}");
var httpClient = new System.Net.Http.HttpClient();
var result = await httpClient.GetAsync(uri);
//user info returnd as JSON
string jsonUserInfo = await result.Content.ReadAsStringAsync();
if (jsonUserInfo != null)
{
var json = Newtonsoft.Json.Linq.JObject.Parse(jsonUserInfo);
string username = json["name"].ToString();
string email = json["emails"]["account"].ToString();
}
我们怎样才能得到用户的照片。 –
@DeviPrasad //通过电话号码获取联系人async任务
如何获得用户帐户的图片 –
@DeviPrasad //获得由电话号码 接触异步任务 _Get_Contact_ByPhone(串TEL) { var contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); var contacts = await contactStore.FindContactsAsync(tel); return contacts.Count> 0? contacts.ElementAt(0):null; } 然后使用'SmallDisplayPicture'或'LargeDisplayPicture'字段获取流。 对不起,标记。 –
jonsbox