2013-11-20 28 views
2

我在我的網站上集成了Google Plus登錄,並且一直運行良好,直到昨天下午5點左右,我的G plus登錄在Chrome中停止工作。無需更改代碼,但按鈕不再工作時,鼠標懸停不會產生手(僅適用於文本選擇),一下子我在控制檯收到幾個未知RPC錯誤:Google Plus登錄 - 未知的RPC服務錯誤

Uncaught TypeError: Cannot read property 'prototype' of undefined VM2122:6 
Unknown RPC service: _ready cb=gapi.loaded_0:64 
Unknown RPC service: _ready cb=gapi.loaded_0:64 
Unknown RPC service: _resizeMe cb=gapi.loaded_0:64 

我認爲這與我的Google Plus登錄按鈕HTML有關,但我無法找到問題所在。我發現this topic,但它是沒有幫助的,我不使用jQuery創建按鈕,只是純HTML:

<div id="gConnect"> 
    <button class="g-signin" 
     data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email" 
     data-requestvisibleactions="http://schemas.google.com/AddActivity" 
     data-clientId="REDACTED" 
     data-callback="onSignInCallback" 
     data-theme="dark" 
     data-cookiepolicy="single_host_origin"> 
    </button> 
</div> 

,並在我的JS:

var helper = (function() { 
    var BASE_API_PATH = 'plus/v1/'; 


    return { 
     /** 
     * Hides the sign in button and starts the post-authorization operations. 
     * 
     * @param {Object} authResult An Object which contains the access token and 
     * other authentication information. 
     */ 


     onSignInCallback: function(authResult) { 
      gapi.client.load('plus','v1', function(){ 
      // $('#authResult').html('Auth Result:<br/>'); 
      // for (var field in authResult) { 
      // $('#authResult').append(' ' + field + ': ' + 
      //  authResult[field] + '<br/>'); 
      // } 


      if (authResult['access_token']) { 
       gapi.auth.setToken(authResult); // Store the returned token. Unnecessary? 
       $('#loggedIn').show('slow'); 
       $('#gConnect').fadeOut('slow'); 
       helper.profile(); 

      } else if (authResult['error']) { 
       // There was an error, which means the user is not signed in. 
       // As an example, you can handle by writing to the console: 
       console.log('The user is not signed in.'); 
       $('#loggedIn').hide('slow'); 
       $('#gConnect').show(); 
      } 

      // console.log('authResult', authResult); 
      }); 
     }, 

     /** 
     * Calls the OAuth2 endpoint to disconnect the app for the user. 
     */ 

     disconnect: function() { 
      // Revoke the access token. 
      $.ajax({ 
      type: 'GET', 
      url: 'https://accounts.google.com/o/oauth2/revoke?token=' + 
       gapi.auth.getToken().access_token, 
      async: false, 
      contentType: 'application/json', 
      dataType: 'jsonp', 
      success: function(result) { 
       console.log('revoke response: ' + result); 
       $('#loggedIn').hide(); 
       $('#profileImg').empty(); 
       $('#greeting').empty(); 
       $('#gConnect').show(); 
      }, 
      error: function(e) { 
       console.log(e); 
      } 
      }); 
     }, 

     /** 
     * Gets and renders the list of people visible to this app. 
     */ 
     people: function() { 
      var request = gapi.client.plus.people.list({ 
      'userId': 'me', 
      'collection': 'visible' 
      }); 
      request.execute(function(people) { 
      $('#visiblePeople').empty(); 
      $('#visiblePeople').append('Number of people visible to this app: ' + 
       people.totalItems + '<br/>'); 
      for (var personIndex in people.items) { 
       person = people.items[personIndex]; 
       $('#visiblePeople').append('<img src="' + person.image.url + '">'); 
      } 
      }); 
     }, 

     /** 
     * Gets and renders the currently signed in user's profile data. 
     */ 
     profile: function() { 

      gapi.client.load('oauth2', 'v2', function() { 

       // get email  
       var request = gapi.client.oauth2.userinfo.get(); 
       request.execute(function(obj) { 
        userInfo.setEmail(obj.email); 
       }); 

       // get profile 
       var request = gapi.client.plus.people.get({'userId' : 'me'}); 
       request.execute(function(profile) { 
        userInfo.setProfile(profile); 
       }); 

      }); 

     } 
    }; 
})(); 


function onSignInCallback(authResult) { 
    helper.onSignInCallback(authResult); 
} 

我一直沒能找到任何有關Google+ API或有此特定問題的其他人的更改文檔。奇怪的一條額外信息是,我仍然可以使用移動瀏覽器(Android)登錄,但該應用程序的功能被破壞(超出本文的範圍)。

回答

1

嘗試啓用您的瀏覽器上的第三方cookie,它應該工作:)

+3

如果這是正確的,你可以詳細說明這一點?指向一些博客文章或文檔?請記住,這是一個Wiki站點,不僅僅是一個討論板。 –

+0

謝謝,這確實是問題所在。很想知道爲什麼這種行爲昨天發生了變化,而且這是記錄在案的。我昨天沒有更改我的Cookie政策,並且它在幾個月前運行(儘管沒有Cookie)而沒有禁用第三方Cookie。 – mpsyp