【发布时间】:2018-03-21 16:43:34
【问题描述】:
我正在开发 Xamarin 跨平台应用程序,并在其中实施 Google 登录。 通过浏览器和邮递员,我能够使用 api 进行身份验证和获取用户数据。 但是当我在 Xamarin 表单 webview 中使用时,我收到了 disallowed_useragent 的错误。
因为 Google 不再支持 webview 请求。所以我需要在 Andriod 和 iOS 应用程序中设置用户代理,或者在 PCL 项目中设置两个平台都会使用的东西。
我没有找到解决这个问题的方法
这是我的代码:
private async void LoginWithGoogle_Clicked(object sender, EventArgs e)
{
ShowLoader(true);
var authRequest =
"https://accounts.google.com/o/oauth2/v2/auth"
+ "?response_type=code"
+ "&scope=email%20profile"
+ "&redirect_uri=" + Constants.GoogleRedirectUri
+ "&client_id=" + Constants.GoogleClientId;
var webView = new WebView
{
Source = authRequest,
HeightRequest = 1
};
webView.Navigated += WebViewOnNavigatedForGoogle;
Content = webView;
ShowLoader(false);
}
【问题讨论】:
标签: android webview xamarin.ios xamarin.forms