如何在我的Cordova Phonegap Android应用程序上从Google Drive获取文件和文件夹列表



i我的cordova应用程序身份验证完成了我也获得了访问令牌。当我调用以获取文件列表的方法时。我显示以下错误消息403 forbbidan

    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
     "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

代码如下

var googleapi = {
    authorize : function(options) {
        var deferred = $.Deferred();
        var authUrl = 'https://accounts.google.com/o/oauth2/auth?' + $.param({
            client_id : options.client_id,
            redirect_uri : options.redirect_uri,
            response_type : 'code',
            scope : options.scope
        });
        var authWindow = window.open(authUrl, '_blank',
                'location=no,toolbar=no');
        $(authWindow).on('loadstart', function(e) {
            var url = e.originalEvent.url;
            var code = /?code=(.+)$/.exec(url);
            var error = /?error=(.+)$/.exec(url);
            if (code || error) {
                authWindow.close();
            }
            if (code) {
                $.post('https://accounts.google.com/o/oauth2/token', {
                    code : code[1],
                    client_id : options.client_id,
                    client_secret : options.client_secret,
                    redirect_uri : options.redirect_uri,
                    grant_type : 'authorization_code'
                }).done(function(data) {
                    deferred.resolve(data);
                }).fail(function(response) {
                    alert("fail");
                    deferred.reject(response.responseJSON);
                });
            } else if (error) {
                alert("reject");
                deferred.reject({
                    error : error[1]
                });
            }
        });
        return deferred.promise();
    }
};
$(document)
        .on(
                'deviceready',
                function() {
                    var deferred = $.Deferred();
                    var $loginButton = $('#login a');
                    var $loginStatus = $('#login p');
                    $loginButton
                            .on(
                                    'click',
                                    function() {
                                    googleapi
                                                .authorize(
                                                        {
                                                        //  client_id : '10901099134-tenshqgdrulrb4r483lcuaami7e7dldt.apps.googleusercontent.com',
                                                        //  client_secret : 'CJ7icaUBFWEwJCV9j_NPqRG8', 
                                                            client_id : '966198539347-h7kjthlnl9t3glsoe0uvgh4km2iogbll.apps.googleusercontent.com',
                                                            client_secret : 'M9CWYuz09StWMZpLin3hb6dt',
                                                            redirect_uri : 'http://localhost',
                                                            scope : 'https://www.googleapis.com/auth/drive.file'
                                                        })
                                                .done(
                                                        function(data) {

                                                            $loginStatus
                                                                    .html('Access security Token: '
                                                                            + data.access_token);
                                                            var Access_Token = data.access_token;
                                                            loadDriveApi();
                                            })
                                                .fail(
                                                        function(data) {
                                                            $loginStatus
                                                                    .html(data.error);
                                                        });
                                    });
                });

function loadDriveApi() {
    gapi.client.load('drive', 'v3',listFiles);
  }
function listFiles() {
  var request = gapi.client.drive.files.list({
      'pageSize': 10,
      'fields': "nextPageToken, files(id, name)"
    });
    request.execute(function(resp) {
      appendPre('Files:');
  var files = resp.files;
      if (files && files.length > 0) {
        for (var i = 0; i < files.length; i++) {
          var file = files[i];
          appendPre(file.name + ' (' + file.id + ')');
        }
      } else {
        appendPre('No files found.');
      }
    });
}
function appendPre(message) {
  var pre = document.getElementById('output');
  var textContent = document.createTextNode(message + 'n');
  pre.appendChild(textContent);
} 

在我的Cordova Android应用程序中执行此代码后,找回找不到文件。并调试器显示了403 Forbiddan。

作为错误消息:

"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

说,您的未经身份用途的每日限制已超过。

我看到您提到您正在使用身份验证API。访问驱动器API时,检查您是否正确接线了access_token,以确保您的API调用使用您的身份验证信息。

最新更新