【问题标题】:xamarin form disallowed_useragent with webview when using Google api使用 Google api 时带有 webview 的 xamarin 表单 disallowed_useragent
【发布时间】: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


    【解决方案1】:

    查看https://github.com/xamarin/Xamarin.Auth,有可行的解决方案:)

    【讨论】:

      猜你喜欢
      • 2018-01-26
      • 2023-03-27
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      • 2017-03-30
      相关资源
      最近更新 更多