ApiException:10:必须请求驱动器#SCOPE_FILE

时间:2017-12-27 09:38:33

标签: android google-api google-drive-api

我正在接受 ApiException :10。我试图通过互联网查找但却一无所获。奇怪的是,我在某些设备上而不是在其他设备上出现此错误,即在某些设备(如仿真器或我的S7)上创建了文件但在某些旧设备上却出现此错误。

我所检查的内容:Google Play服务在所有运行相同版本的设备上都是最新的,所以我猜这可以排除。

代码

    private void createNewFile(){
    final File file = getApplicationContext().getDatabasePath("eventManager");
    if(mDriveResourceClient!=null){
        Log.i(TAG,"Beginning Writing");
        final Task<DriveFolder> rootFolderTask = mDriveResourceClient.getRootFolder();
        final Task<DriveContents> createContentsTask = mDriveResourceClient.createContents();
        Tasks.whenAll(rootFolderTask, createContentsTask)
                .continueWithTask(new Continuation<Void, Task< DriveFile>>(){
                    @Override
                    public Task<DriveFile> then(Task<Void> task) throws Exception{
                        Log.i(TAG,"Writing task started");
                        DriveFolder parent = rootFolderTask.getResult();
                        DriveContents contents = createContentsTask.getResult();
                        OutputStream outputStream = contents.getOutputStream();
                        try{
                            InputStream inputStream = new FileInputStream(file);
                            byte[] buf = new byte[4096];
                            int c;
                            while((c = inputStream.read(buf, 0, buf.length))>0){
                                outputStream.write(buf, 0, c);
                            }
                        }catch (Exception e) {
                            Log.i(TAG,"Writing task failed");

                        }finally {
                            outputStream.close();
                        }
                        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                                .setTitle("My_File")
                                .setMimeType("application/x-sqlite3")
                                .setStarred(true)
                                .build();
                        Log.i(TAG,"Writing task started");
                        return mDriveResourceClient.createFile(parent, changeSet, contents);

                    }
                })
                .addOnSuccessListener(this,
                        new OnSuccessListener<DriveFile>() {
                            @Override
                            public void onSuccess(DriveFile driveFile) {
                                Toast.makeText(getApplicationContext(), "File Saved", Toast.LENGTH_SHORT).show();
                            }
                        })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e(TAG, "Unable to create file", e);
                        Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_SHORT).show();
                    }
                });
    }
}
  

错误:12-27 14:57:26.723 30393-30393 /? E / MainActivity:无法创建文件                                                    com.google.android.gms.common.api.ApiException:10:必须请求驱动器#SCOPE_FILE                                                        在com.google.android.gms.internal.zzbna.zza(未知来源)                                                        在com.google.android.gms.common.api.internal.zze.zza(未知来源)                                                        在com.google.android.gms.common.api.internal.zzbr.zzb(未知来源)                                                        在com.google.android.gms.common.api.internal.zzbr.zza(未知来源)                                                        在com.google.android.gms.common.api.internal.zzbp.handleMessage(未知来源)                                                        在android.os.Handler.dispatchMessage(Handler.java:98)                                                        在android.os.Looper.loop(Looper.java:148)                                                        在android.os.HandlerThread.run(HandlerThread.java:61)

0 个答案:

没有答案