当前位置: 首页>>代码示例>>Java>>正文


Java DriveScopes类代码示例

本文整理汇总了Java中com.google.api.services.drive.DriveScopes的典型用法代码示例。如果您正苦于以下问题:Java DriveScopes类的具体用法?Java DriveScopes怎么用?Java DriveScopes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DriveScopes类属于com.google.api.services.drive包,在下文中一共展示了DriveScopes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 */
public static void authorize(String userID, boolean driveAPI) throws IOException {
    // load client secrets

    // set up authorization code flow
    Collection<String> scopes = new ArrayList<String>();
    scopes.add(GamesScopes.GAMES);
    if (driveAPI)
        scopes.add(DriveScopes.DRIVE_APPDATA);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build();
    // authorize
    Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) {
        // Override open browser not working well on Linux and maybe other
        // OS.
        protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws java.io.IOException {
            Gdx.net.openURI(authorizationUrl.build());
        }
    }.authorize(userID);

    games = new Games.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build();
    if (driveAPI)
        drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build();

}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:29,代码来源:GApiGateway.java

示例2: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(Configuration.JSON_FACTORY,
            new InputStreamReader(Main.class.getResourceAsStream("/client_secrets/client_secrets.json")));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive "
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            Configuration.httpTransport, Configuration.JSON_FACTORY, clientSecrets,DriveScopes.all()
            ).setDataStoreFactory(Configuration.dataStoreFactory)
            .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:atuljangra,项目名称:ExcelToGoogleSpreadSheet,代码行数:22,代码来源:Authorization.java

示例3: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
private Credential authorize(final IProgressMonitor monitor) throws IOException {
	try {
		monitor.beginTask("Authorizes the application to access user's protected data on Google Drive", 100);
		// load client secrets
		// In this context, the client secret is obviously not treated as a
		// secret.
		GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
				new InputStreamReader(GDriveConnectionManager.class.getResourceAsStream("client_secrets.json")));
		// set up authorization code flow
		FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataStoreDir);
		GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
				clientSecrets, Collections.singleton(DriveScopes.DRIVE)).setDataStoreFactory(dataStoreFactory)
						.build();
		// authorize
		LocalServerReceiver localServerReceiver = new CancellableLocalServerReceiver(monitor);
		AuthorizationCodeInstalledApp authorizationCodeInstalledApp = authorizationCodeInstalledAppProvider
				.get(flow, localServerReceiver, monitor);
		return authorizationCodeInstalledApp.authorize("user");
	} finally {
		monitor.done();
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:23,代码来源:GDriveConnectionManager.java

示例4: GoogleDriveAuthorizer

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
public GoogleDriveAuthorizer(AuthSecretFile secretFile) {
    super(APP_NAME, CLIENT_ID, secretFile, AuthSecretKey.GoogleDrive);

    this.auth = new GoogleAuthorizationCodeFlow.Builder(
            this.httpTransport,
            this.jsonFactory,
            getAppId(),
            getAppSecret(),
            Arrays.asList(DriveScopes.DRIVE)
    ).setAccessType("offline").setApprovalPrompt("auto").build();

    this.refreshListener = new GoogleDriveRefreshListener();

    this.credentialBuilder = new GoogleCredential.Builder()
            .setClientSecrets(getAppId(), getAppSecret())
            .setJsonFactory(this.jsonFactory)
            .setTransport(this.httpTransport)
            .addRefreshListener(this.refreshListener);
}
 
开发者ID:omnidrive,项目名称:omnidrive,代码行数:20,代码来源:GoogleDriveAuthorizer.java

示例5: onAuthentication

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
@Override
public void onAuthentication(Credentials credentials) {
    Log.i(TAG, "Auth ok! User has given us all google requested permissions.");
    AuthenticationAPIClient client = new AuthenticationAPIClient(getAccount());
    client.tokenInfo(credentials.getIdToken())
            .start(new BaseCallback<UserProfile, AuthenticationException>() {
                @Override
                public void onSuccess(UserProfile payload) {
                    final GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(FilesActivity.this, Collections.singletonList(DriveScopes.DRIVE_METADATA_READONLY));
                    credential.setSelectedAccountName(payload.getEmail());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            new FetchFilesTask().execute(credential);
                        }
                    });
                }

                @Override
                public void onFailure(AuthenticationException error) {
                }
            });

}
 
开发者ID:auth0,项目名称:Lock-Google.Android,代码行数:25,代码来源:FilesActivity.java

示例6: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
static Credential authorize(String clientId, String clientSecret, String credentialsPath, String credentialStore,
                            HttpTransport httpTransport, JsonFactory jsonFactory) throws IOException {
    GoogleClientSecrets.Details installedDetails = new GoogleClientSecrets.Details();
    installedDetails.setClientId(clientId);
    installedDetails.setClientSecret(clientSecret);

    GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
    clientSecrets.setInstalled(installedDetails);

    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new java.io.File(credentialsPath));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialStore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
            clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE))
            .setCredentialDataStore(datastore)
            .build();

    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:donbeave,项目名称:grails-google-drive,代码行数:20,代码来源:GoogleDrive.java

示例7: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
protected Credential authorize() throws GoogleException, GeneralSecurityException, IOException {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretsResource.getInputStream());
    if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        LOGGER.error("Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive " + "into "
                + clientSecretsResource.getFile().getAbsolutePath());
        throw new GoogleException("ClientSecrets not configured");
    }
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(userCredentialStoreResource.getFile(), JSON_FACTORY);
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
            Collections.singleton(DriveScopes.DRIVE_FILE)).setCredentialStore(credentialStore).build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, verificationCodeReceiver).authorize(user);
}
 
开发者ID:acxio,项目名称:AGIA,代码行数:17,代码来源:GoogleDriveServiceImpl.java

示例8: startUpload

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
public void startUpload(View view) {

        if (isConnected) {
            if (isScannedOnce) {
                if (credential != null) {
                    uploadFileToDrive();
                } else {
                    credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE));
                    startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_UPLOAD);
                }

            } else {
                showToast("Must scan before upload");
            }
        }
    }
 
开发者ID:s-papanastasiou,项目名称:wireless-positioning,代码行数:17,代码来源:DetectorActivity.java

示例9: getDrive

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
public static Drive getDrive() throws IOException, Docx4JException {
 
  HttpTransport httpTransport = new NetHttpTransport();
  JsonFactory jsonFactory = new JacksonFactory();
 
  GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, jsonFactory, getClientSecrets(jsonFactory), Arrays.asList(DriveScopes.DRIVE))
      .setAccessType("online")
      .setApprovalPrompt("auto").build();
  
  String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
  System.out.println("Please open the following URL in your browser then type the authorization code:");
  System.out.println("  " + url);
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String code = br.readLine();
  
  GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
  GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);
  
  //Create a new authorized API client
  return new Drive.Builder(httpTransport, jsonFactory, credential).build();
  
}
 
开发者ID:plutext,项目名称:docx4j-cloud-GoogleDrive,代码行数:24,代码来源:CredentialsViaCommandLine.java

示例10: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/**
 * Obtains credentials using the preferred authorization method.
 *
 * @return
 * @throws Exception
 */
@Override
public Credential authorize() throws Exception
{
    SCOPES.add(DriveScopes.DRIVE);
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

    // Authorize
    Credential credential = authorizeServiceAccount();

    // Get token
    credential.refreshToken();
    logger.debug("Access token: {}", credential.getAccessToken());
    logger.debug("Expires in {} seconds", credential.getExpiresInSeconds());
    return credential;
}
 
开发者ID:mkrause,项目名称:gx,代码行数:22,代码来源:ServiceAccountAuthorizer.java

示例11: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/**
 * Obtains credentials using the preferred authorization method.
 *
 * @return
 * @throws Exception
 */
@Override
public Credential authorize() throws Exception
{
    SCOPES.add(DriveScopes.DRIVE);
    CREDENTIAL_FILE = System.getProperty("user.home") + "/.credentials/oauth2.json";
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

    // load client secrets
    InputStream s = new FileInputStream(CLIENT_SECRETS_FILE);
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, s);

    // Authorize
    Credential credential = authorizeUser(clientSecrets);

    // Get token
    credential.refreshToken();
    logger.debug("Access token: {}", credential.getAccessToken());
    logger.debug("Expires in {} seconds", credential.getExpiresInSeconds());
    return credential;
}
 
开发者ID:mkrause,项目名称:gx,代码行数:27,代码来源:GooglePromptAuthorizer.java

示例12: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/**
 * Obtains credentials using the preferred authorization method.
 *
 * @return
 * @throws Exception
 */
private static Credential authorize() throws Exception
{
    SCOPES.add(DriveScopes.DRIVE);
    CREDENTIAL_FILE = System.getProperty("user.home") + "/.credentials/oauth2.json";
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

    // load client secrets
    InputStream s = new FileInputStream(CLIENT_SECRETS_FILE);
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, s);
    appId = getAppId(clientSecrets);

    // Authorize
    Credential credential = USE_SERVICE_ACCOUNT ? authorizeServiceAccount() : authorizeUser(clientSecrets);

    // Get token
    credential.refreshToken();
    logger.debug("Access token: {}", credential.getAccessToken());
    logger.debug("Expires in {} seconds", credential.getExpiresInSeconds());
    return credential;
}
 
开发者ID:mkrause,项目名称:gx,代码行数:27,代码来源:BrowserChannelTest.java

示例13: authorize

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private Credential authorize() throws Exception {
	// load client secrets
	GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
			new InputStreamReader(GFile.class.getResourceAsStream("/client_secrets.json")));
	if (clientSecrets.getDetails().getClientId().startsWith("Enter")
			|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
		System.out.println("Overwrite the src/main/resources/client_secrets.json file with the client secrets file "
				+ "you downloaded from the Quickstart tool or manually enter your Client ID and Secret "
				+ "from https://code.google.com/apis/console/?api=drive#project:275751503302 "
				+ "into src/main/resources/client_secrets.json");
		System.exit(1);
	}
	// set up authorization code flow
	Set<String> scopes = new HashSet<String>();
	scopes.add(DriveScopes.DRIVE);
	scopes.add(DriveScopes.DRIVE_METADATA);

	GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes)
			.setDataStoreFactory(dataStoreFactory).build();
	// authorize
	return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:andresoviedo,项目名称:google-drive-ftp-adapter,代码行数:24,代码来源:GoogleDrive.java

示例14: create

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:33,代码来源:GoogleDriveClient.java

示例15: create

import com.google.api.services.drive.DriveScopes; //导入依赖的package包/类
public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
    String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:34,代码来源:GoogleDrivePictureClient.java


注:本文中的com.google.api.services.drive.DriveScopes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。