Google Plus登录 - 未知的RPC服务错误

时间:2013-11-20 10:59:03

标签: javascript login google-plus

我已经在我的网站上集成了Google Plus登录,并且一直运行良好,直到昨天下午5点左右,我的G plus登录停止在Chrome中工作。没有更改代码,但按钮不再有效,鼠标悬停不会产生一只手(只有一个文本选择),突然间我在控制台中收到了几个未知的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 个答案:

答案 0 :(得分:1)

尝试在浏览器上启用第三方Cookie,它应该有效:)