【问题标题】:Google Cloud API OAuth2 doesn't work on any iphone browsersGoogle Cloud API OAuth2 不适用于任何 iPhone 浏览器
【发布时间】:2021-10-15 05:18:27
【问题描述】:

我正在开发一个简单的仪表板,该仪表板要求用户通过 gapi 登录并授予其 Google 日历的权限。直接来自 Calendar Quickstart 的代码在我的 Macbook Pro 和 Android 上运行的所有浏览器上都能完美运行,但在我的 iPhone 12 上运行的任何浏览器上几乎没有反应。我尝试过 Chrome、Safari 和 DuckDuckGo。

如果我从 iOS 上的这些浏览器之一清除数据,我将能够进入 Google 登录流程,但重定向就像什么都没发生一样; gapi.auth2.getAuthInstance().isSignedIn.get() 返回错误。之后,单击“授权”按钮(如果您确实没有登录,它应该会带您进入 Google 登录)基本上只是刷新了页面。

我收到的唯一错误消息是以下警告(iOS 中的 Safari):

代码如下:

function initClient() {
  let phoneNumber = new URLSearchParams(window.location.search).get('number');
  if(phoneNumber !== null){
    window.localStorage.setItem('numberForNewUser', phoneNumber)
  }
  gapi.client
    .init({
      apiKey: 'API_KEY',
      clientId: 'CLIENT_ID',
      discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest'],
      scope: 'https://www.googleapis.com/auth/calendar',
      ux_mode: 'redirect',
    })
    .then(
      function () {
        let authInstance = gapi.auth2.getAuthInstance();
        // Listen for sign-in state changes.
        authInstance.isSignedIn.listen(updateSigninStatus);

        // Handle the initial sign-in state.
        updateSigninStatus(authInstance.isSignedIn.get());
        
        authorizeButton.onclick = handleAuthClick;
        signoutButton.onclick = handleSignoutClick;
      },
      function (error) {
        console.log(error);
      }
    )
}

let authorizeButton = document.getElementById('authorize_button');
let signoutButton = document.getElementById('signout_button');
let profileContainer = document.getElementById('profile_info')

function handleAuthClick(event) {
  gapi.auth2.getAuthInstance().signIn();
}

function handleSignoutClick(event) {
  gapi.auth2.getAuthInstance().signOut();
  document.getElementById('loggedin_container').style.display = 'none'
}

虽然似乎无休止地搜索,但我尝试了解决方案like this,但无济于事。任何其他建议将不胜感激!

【问题讨论】:

    标签: javascript ios google-oauth google-calendar-api


    【解决方案1】:

    终于找到this answer;重定向在 iOS 上不起作用,但弹出窗口可以。不理想,但目前已经足够了。

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2011-04-22
      相关资源
      最近更新 更多