Google Drive Api获取问题

时间:2016-02-07 05:19:40

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

不知道导致问题的原因真是令人沮丧,我试图在用户Google云端硬盘中留下总配额和总可用空间, 以下是我的代码摘要,代码崩溃在“com.google.api.services.drive.model.About about = mGooSvc.about()。get()。execute();”错误堆栈位于底部

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.Drive;

//within Class variables declared
private static com.google.api.services.drive.Drive mGooSvc;
    private static com.google.api.services.drive.Drive m_client;
    private final HttpTransport m_transport = AndroidHttp.newCompatibleTransport();
    private final JsonFactory m_jsonFactory = GsonFactory.getDefaultInstance();
    private GoogleAccountCredential m_credential;
    private static Drive service;

//with in protected void onCreate(Bundle savedInstanceState)
   //GoogleDrive
        m_credential=GoogleAccountCredential.usingOAuth2(this, Collections.singleton(DriveScopes.DRIVE));
        //Drive
                m_client = new com.google.api.services.drive.Drive.Builder(
                m_transport, m_jsonFactory, m_credential).setApplicationName("com.dbprox.css")
                .build();
        mGooSvc = new com.google.api.services.drive.Drive.Builder(
                m_transport,m_jsonFactory,m_credential.usingOAuth2(
               getApplicationContext(),
                Collections.singletonList(com.google.api.services.drive.DriveScopes.DRIVE_FILE))).build();



//on button click Listener
 startActivityForResult(m_credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);

//onActivityResult

if ((requestCode == REQUEST_ACCOUNT_PICKER || requestCode == REQUEST_CODE_RESOLUTION)) {
            if (resultCode == RESULT_OK) {
                if (data != null && data.getExtras() != null) {
                    String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME);
                    if (accountName != null) {
                       m_credential.setSelectedAccountName(accountName);
                    Toast.makeText(this,m_credential.getSelectedAccountName(),Toast.LENGTH_LONG).show();
                    }
                }
                // call method to start accessing Google Drive

                try {

                   // com.google.api.services.drive.model.About about = mGooSvc.about().get().execute();
                 com.google.api.services.drive.model.About about = mGooSvc.about().get().execute();//  service.about().get().execute(); //service.about().get().execute();

                    Log.i("Google Drive",about.getStorageQuota().getLimit().toString());
//                    System.out.println("Current user name: " + about.getStorageQuota().getLimit().toString());

                    // TOTAL - USED = FREE SPACE
                } catch (IOException e) {
                    System.out.println("An error occurred: " + e);
                }
            }

        }else {
          super.onActivityResult(requestCode, resultCode, data);}

下面是Stack Trace

02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:引起:java.lang.IllegalArgumentException:名称不能为空:null 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.accounts.Account。(Account.java:48) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:255) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential $ RequestHandler.intercept(GoogleAccountCredential.java: 279) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.dbprox.css.MainActivity.onActivityResult(MainActivity.java:244) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.app.Activity.dispatchActivityResult(Activity.java:5552) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.app.ActivityThread.deliverResults(ActivityThread.java:3591) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.app.ActivityThread.handleSendResult(ActivityThread.java:3638) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.app.ActivityThread.access $ 1300(ActivityThread.java:154) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1393) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.os.Handler.dispatchMessage(Handler.java:110) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at android.os.Looper.loop(Looper.java:193) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:在android.app.ActivityThread.main(ActivityThread.java:5347) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at java.lang.reflect.Method.invokeNative(Native Method) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at java.lang.reflect.Method.invoke(Method.java:515) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:835) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651) 02-07 13:16:34.414 27038-27038 / com.dbprox.css E / AndroidRuntime:at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案