【问题标题】:How can I use Google's people API in Xamarin.iOS?如何在 Xamarin.iOS 中使用 Google 的人员 API?
【发布时间】:2020-02-11 13:13:42
【问题描述】:
我必须在我们的 Xamarin 中访问 Google 联系人。 ios app 所以,我们在Google developer portal 中生成了Google 的人员API 密钥和客户端ID
但我不知道如何在 Xamarin.ios 应用程序中使用 API。我们需要使用 API 获取 Google 联系方式。
我们在 Google 文档中获得了一些 .net 代码,但不幸的是,它不适用于 Xamarin.ios 平台。 xamarin 平台不支持 DLL。
请帮我解决这个问题。
【问题讨论】:
标签:
xamarin
xamarin.ios-binding
【解决方案1】:
我已经通过使用 Xamarin.Auth 库解决了这个问题。
Auth = new OAuth2Authenticator(
Configuration.ClientId,
string.Empty,
"https://www.googleapis.com/auth/contacts",
new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
new Uri(Configuration.RedirectUrl),
new Uri("https://www.googleapis.com/oauth2/v4/token"),
isUsingNativeUI: true);
var viewController = Auth.GetUI();
PresentViewController(viewController, true, null);
Auth.Completed += Auth_Completed;
Auth.Error += Auth_Error;
private void Auth_Error(object sender, AuthenticatorErrorEventArgs e)
{
}
private void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e)
{
// SFSafariViewController doesn't dismiss itself
DismissViewController(true, null);
if (e.IsAuthenticated)
{
}
}
必须在 Appdelegate.cs 中实现 OpentUrl() 直到 iOS 12 及更高版本 iOS 13 在 SceneDelegate.cs 中实现 OpenUrlContexts() 方法