Google drive api 我在哪里提出针对驱动器SDK的错误?

Google drive api 我在哪里提出针对驱动器SDK的错误?,google-drive-api,Google Drive Api,下面的代码一致地给出了以下结果 Summary... File insert attempts (a) = 100 rate limit errors (b) = 31 expected number of files (a-b) = 69 Actual number of files = 73 …表示尽管引发403速率限制异常,驱动器有时还是会插入文件 package com.cnw.test.servlets; import java.io

下面的代码一致地给出了以下结果

Summary...
File insert attempts (a)       = 100
rate limit errors (b)          = 31
expected number of files (a-b) = 69
Actual number of files         = 73 
…表示尽管引发403速率限制异常,驱动器有时还是会插入文件

package com.cnw.test.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.ChildList;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.File.Labels;
import com.google.api.services.drive.model.ParentReference;

import couk.cleverthinking.cnw.oauth.CredentialMediatorB;
import couk.cleverthinking.cnw.oauth.CredentialMediatorB.InvalidClientSecretsException;

@SuppressWarnings("serial")
    /**
     * 
     * AppEngine servlet to demonstrate that Drive IS performing an insert despite throwing a 403 rate limit exception.
     * 
     * All it does is create a folder, then loop to create x files. Any 403 rate limit exceptions are counted.
     * At the end, compare the expected number of file (attempted - 403) vs. the actual.
     * In a run of 100 files, I consistently see between 1 and 3 more files than expected, ie. despite throwing a 403 rate limit,
     * Drive *sometimes* creates the file anyway.
     * 
     * To run this, you will need to ...
     * 1) enter an APPNAME above
     * 2) enter a google user id above
     * 3) Have a valid stored credential for that user
     * 
     * (2) and (3) can be replaced by a manually constructed Credential 
     * 
     * Your test must generate rate limit errors, so if you have a very slow connection, you might need to run 2 or 3 in parallel. 
     * I run the test on a medium speed connection and I see 403 rate limits after 30 or so inserts.
     * Creating 100 files consistently exposes the problem.
     * 
     */
public class Hack extends HttpServlet {

    private final String APPNAME = "MyApp";  // ENTER YOUR APP NAME
    private final String GOOGLE_USER_ID_TO_FETCH_CREDENTIAL = "11222222222222222222222"; //ENTER YOUR GOOGLE USER ID
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        /*
         *  set up the counters
         */
        // I run this as a servlet, so I get the number of files from the request URL
        int numFiles = Integer.parseInt(request.getParameter("numfiles"));
        int fileCount = 0;
        int ratelimitCount = 0;

        /*
         * Load the Credential
         */
        CredentialMediatorB cmb = null;
        try {
            cmb = new CredentialMediatorB(request);
        } catch (InvalidClientSecretsException e) {
            e.printStackTrace();
        }
        // this fetches a stored credential, you might choose to construct one manually
        Credential credential = cmb.getStoredCredential(GOOGLE_USER_ID_TO_FETCH_CREDENTIAL);

        /*
         * Use the credential to create a drive service
         */
        Drive driveService = new Drive.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName(APPNAME).build();

        /* 
         * make a parent folder to make it easier to count the files and delete them after the test
         */
        File folderParent = new File();
        folderParent.setTitle("403parentfolder-" + numFiles);
        folderParent.setMimeType("application/vnd.google-apps.folder");
        folderParent.setParents(Arrays.asList(new ParentReference().setId("root")));
        folderParent.setLabels(new Labels().setHidden(false));
        driveService.files().list().execute();
        folderParent = driveService.files().insert(folderParent).execute();
        System.out.println("folder made with id = " + folderParent.getId());

        /*
         * store the parent folder id in a parent array for use by each child file
         */
        List<ParentReference> parents = new ArrayList<ParentReference>();
        parents.add(new ParentReference().setId(folderParent.getId()));

        /*
         * loop for each file
         */
        for (fileCount = 0; fileCount < numFiles; fileCount++) {
            /*
             * make a File object for the insert
             */
            File file = new File();
            file.setTitle("testfile-" + (fileCount+1));
            file.setParents(parents);
            file.setDescription("description");
            file.setMimeType("text/html");

            try {
                System.out.println("making file "+fileCount + " of "+numFiles);
                // call the drive service insert execute method 
                driveService.files().insert(file).setConvert(false).execute();
            } catch (GoogleJsonResponseException e) {
                GoogleJsonError error = e.getDetails();
                // look for rate errors and count them. Normally one would expo-backoff here, but this is to demonstrate that despite
                // the 403, the file DID get created
                if (error.getCode() == 403 && error.getMessage().toLowerCase().contains("rate limit")) {
                    System.out.println("rate limit exception on file " + fileCount + " of "+numFiles);
                    // increment a count of rate limit errors
                    ratelimitCount++;
                } else {
                    // just in case there is a different exception thrown
                    System.out.println("[DbSA465] Error message: " + error.getCode() + " " + error.getMessage());
                }
            }
        }

        /* 
         * all done. get the children of the folder to see how many files were actually created
         */
        ChildList children = driveService.children().list(folderParent.getId()).execute();

        /*
         * and the winner is ...
         */
        System.out.println("\nSummary...");
        System.out.println("File insert attempts (a)       = " + numFiles);
        System.out.println("rate limit errors (b)          = " + ratelimitCount);
        System.out.println("expected number of files (a-b) = " + (numFiles - ratelimitCount));
        System.out.println("Actual number of files         = " + children.getItems().size() + " NB. There is a limit of 100 children in a single page, so if you're expecting more than 100, need to follow nextPageToken");
    }
}
package com.cnw.test.servlets;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.List;
导入javax.servlet.http.HttpServlet;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
导入com.google.api.client.auth.oauth2.Credential;
导入com.google.api.client.googleapis.json.GoogleJsonError;
导入com.google.api.client.googleapis.json.GoogleJsonResponseException;
导入com.google.api.client.http.javanet.NetHttpTransport;
导入com.google.api.client.json.jackson.JacksonFactory;
导入com.google.api.services.drive.drive;
导入com.google.api.services.drive.model.ChildList;
导入com.google.api.services.drive.model.File;
导入com.google.api.services.drive.model.File.Labels;
导入com.google.api.services.drive.model.ParentReference;
进口couk.cleverthinking.cnw.oauth.CredentialMediatorB;
导入couk.cleverthinking.cnw.oauth.CredentialMediatorB.InvalidClientSecretsException;
@抑制警告(“串行”)
/**
* 
*AppEngine servlet演示尽管引发403速率限制异常,驱动器仍在执行插入。
* 
*它所做的只是创建一个文件夹,然后循环创建x文件。任何403费率限制例外情况均被计算在内。
*最后,比较预期的文件数(尝试的-403)与实际的文件数。
*在运行100个文件时,我始终看到比预期多1到3个文件,即,尽管设置了403速率限制,
*驱动器*有时*会创建文件。
* 
*要运行此功能,您需要。。。
*1)在上面输入APPNAME
*2)在上面输入谷歌用户id
*3)具有该用户的有效存储凭据
* 
*(2)和(3)可由手动构造的凭证替换
* 
*您的测试必须生成速率限制错误,所以如果您的连接非常慢,您可能需要并行运行2或3。
*我在中速连接上运行测试,在大约30次插入后,我看到403个速率限制。
*持续创建100个文件会暴露问题。
* 
*/
公共类Hack扩展了HttpServlet{
私有最终字符串APPNAME=“MyApp”;//输入您的应用程序名称
私有最终字符串GOOGLE_USER_ID_TO_FETCH_CREDENTIAL=“1122222222”//输入您的GOOGLE用户ID
@凌驾
public void doGet(HttpServletRequest请求、HttpServletResponse响应)引发IOException{
/*
*设置柜台
*/
//我将其作为servlet运行,因此从请求URL获取文件数
int numFiles=Integer.parseInt(request.getParameter(“numFiles”);
int fileCount=0;
int-ratelimitCount=0;
/*
*加载凭证
*/
CredentialMediatorB cmb=null;
试一试{
cmb=新的凭证EDIATORB(请求);
}捕获(InvalidClientSecretSexException e){
e、 printStackTrace();
}
//这将获取存储的凭证,您可以选择手动构造凭证
凭证凭证=cmb.getStoredCredential(谷歌用户ID到获取凭证);
/*
*使用凭据创建驱动器服务
*/
Drive driveService=new Drive.Builder(new NetHttpTransport(),new JacksonFactory(),credential).setApplicationName(APPNAME).build();
/* 
*创建一个父文件夹,以便在测试后更轻松地对文件进行计数和删除
*/
File folderParent=新文件();
setTitle(“403parentfolder-”+numFiles);
folderParent.setMimeType(“application/vnd.googleapps.folder”);
folderParent.setParents(Arrays.asList(newparentreference().setId(“根”));
setLabels(新标签().setHidden(false));
driveService.files().list().execute();
folderParent=driveService.files().insert(folderParent.execute();
System.out.println(“用id=“+folderParent.getId()创建的文件夹”);
/*
*将父文件夹id存储在父数组中,供每个子文件使用
*/
List parents=new ArrayList();
add(newparentreference().setId(folderParent.getId());
/*
*循环每个文件
*/
对于(fileCount=0;fileCount