當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleClientSecrets.load方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.load方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleClientSecrets.load方法的具體用法?Java GoogleClientSecrets.load怎麽用?Java GoogleClientSecrets.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets的用法示例。


在下文中一共展示了GoogleClientSecrets.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes list of scopes needed to run youtube upload.
 * @param clientSecret the client secret from Google API console
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 */
public static Credential authorize(
    Collection<String> scopes, String clientSecret, String credentialDatastore)
    throws IOException {
  // Load client secrets
  GoogleClientSecrets clientSecrets =
      GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecret));

  // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
  FileDataStoreFactory fileDataStoreFactory =
      new FileDataStoreFactory(new File(getCredentialsDirectory()));
  DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

  GoogleAuthorizationCodeFlow flow =
      new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
          .setCredentialDataStore(datastore)
          .build();

  // authorize
  return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
開發者ID:youtube,項目名稱:youtube-chat-for-minecraft,代碼行數:28,代碼來源:Auth.java

示例2: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 * @return an authorized Credential object.
 * @throws IOException
 */
public static void authorize() throws IOException {
    // Load client secrets.
    InputStream in = Authorization.class.getClass().getResourceAsStream("/gallery/configs/client_id.json");
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();
    
    Credential credential = new AuthorizationCodeInstalledApp(
        flow, new LocalServerReceiver()).authorize(NICK);
    
    System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
    MAIN = credential;
}
 
開發者ID:Obsidiam,項目名稱:joanne,代碼行數:26,代碼來源:Authorization.java

示例3: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 * @return an authorized Credential object.
 * @throws Exception 
 */
public static Credential authorize() throws Exception {
	// Load client secrets.
	InputStream in =
			SpreadsheetUtils.class.getResourceAsStream("/client_secret.json");
	GoogleClientSecrets clientSecrets =
			GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

	// Build flow and trigger user authorization request.
	GoogleAuthorizationCodeFlow flow =
			new GoogleAuthorizationCodeFlow.Builder(
					HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
			.setDataStoreFactory(DATA_STORE_FACTORY)
			.setAccessType("offline")
			.build();
	Credential credential = new AuthorizationCodeInstalledApp(
			flow, new LocalServerReceiver()).authorize("user");
	System.out.println(
			"Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
	return credential;
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:26,代碼來源:SpreadsheetUtils.java

示例4: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 *
 * @return an authorized Credential object.
 * @throws IOException
 */
public static Credential authorize() throws IOException {
    // Load client secrets.
    InputStream in =
            Login.class.getResourceAsStream("/client_secret.json");
    GoogleClientSecrets clientSecrets =
            GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                    .setDataStoreFactory(DATA_STORE_FACTORY)
                    .setAccessType("offline")
                    .build();
    Credential credential = new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize("user");
    System.out.println(
            "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
    return credential;
}
 
開發者ID:ashoknailwal,項目名稱:desktop-gmail-client,代碼行數:27,代碼來源:Login.java

示例5: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 * @return an authorized Credential object.
 * @throws ResourceServerException Incorrect authorization
 */
public static Credential authorize() {
    // Load client secrets.
    final InputStream in =
            GoogleStorageServiceImpl.class.getResourceAsStream("/client_secret.json");
    Credential credential;
    try {
        final GoogleClientSecrets clientSecrets =
                GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

        // Build flow and trigger user authorization request.
        final GoogleAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow.Builder(
                        HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                        .setDataStoreFactory(DATA_STORE_FACTORY)
                        .setAccessType("offline")
                        .build();
        credential = new AuthorizationCodeInstalledApp(
                flow, new LocalServerReceiver()).authorize("user");
    } catch (final IOException e) {
        throw new ResourceServerException("Incorrect authorization", e);
    }
    return credential;
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:29,代碼來源:GoogleStorageServiceImpl.java

示例6: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
  // load client secrets
 Reader in = new FileReader("Local directory path for client_secrets.json file");
  GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, in);
  if (clientSecrets.getDetails().getClientId().startsWith("Your ")
      || clientSecrets.getDetails().getClientSecret().startsWith("Your ")) {
    System.out.println(
        "Enter Client ID and Secret from https://code.google.com/apis/console/?api=plus "
        + "into client_secrets.json");
    System.exit(1);
  }
  // set up authorization code flow
  GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, JSON_FACTORY, clientSecrets,
      Collections.singleton(PlusScopes.PLUS_ME)).setDataStoreFactory(
      dataStoreFactory).build();
  // authorize
  return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
開發者ID:sshubhadeep,項目名稱:GooglePlusJavaImplementation,代碼行數:21,代碼來源:GooglePlusConsoleDisplay.java

示例7: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates a new authorized Credential object from a response token
 * @param token (String)
 * @param userId (String)
 * @return an authorized Credential object.
 * @throws IOException
 */
public static Credential authorize(String token, String userId) throws IOException
{
    // Load client secrets.
    InputStream in = new FileInputStream(Main.getBotSettingsManager().getGoogleOAuthSecret());
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = (new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES))
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();

    // remove any account previously associated with the token
    flow.getCredentialDataStore().delete(userId);

    // create the new credential
    GoogleTokenResponse response = flow.newTokenRequest(token)
            .setRedirectUri(clientSecrets.getDetails().getRedirectUris().get(0)).execute();
    return flow.createAndStoreCredential(response, userId);
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:28,代碼來源:GoogleAuth.java

示例8: newAuthorizationUrl

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 *
 * @return
 * @throws IOException
 */
public static String newAuthorizationUrl() throws IOException
{
    // Load client secrets.
    InputStream in = new FileInputStream(Main.getBotSettingsManager().getGoogleOAuthSecret());
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = (new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES))
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();

    return flow.newAuthorizationUrl()
            .setScopes(SCOPES)
            .setAccessType("offline")
            .setClientId(clientSecrets.getDetails().getClientId())
            .setRedirectUri(clientSecrets.getDetails().getRedirectUris().get(0))
            .toString();
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:25,代碼來源:GoogleAuth.java

示例9: GoogleConnector

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Instances the google connector configuring all required resources.
 */
private GoogleConnector() throws IOException, GeneralSecurityException {
    super();
    // 1. JSON library
    jsonFactory = JacksonFactory.getDefaultInstance();

    // 2. Configure HTTP transport
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // 3. Load the credentials
    secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleConnector.class.getResourceAsStream("client-secrets.json")));

    // 4. Configure the authentication flow
    dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY);

    // 5. Create flow
    imp_buildAuthorizationFlow();
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:21,代碼來源:GoogleConnector.java

示例10: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/***
 * Crates a Credential object authorized by the Google API.
 * @return an authorized Credential object.
 * @throws IOException
 */
public static Credential authorize() throws IOException{
	InputStream in = CalendarAPI.class.getResourceAsStream("resources/client_secret.json");
   
	if(in == null) throw new IOException("Client information not found.");

	GoogleClientSecrets secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(in));

	GoogleAuthorizationCodeFlow flow =
			new GoogleAuthorizationCodeFlow.Builder(
					http, jsonFactory, secrets, scopes)
					.setDataStoreFactory(dataFactory)
					.setAccessType("offline")
					.build();
	Credential cred = new AuthorizationCodeInstalledApp(
			flow, new LocalServerReceiver()).authorize("user");
	return cred;
}
 
開發者ID:beesenpai,項目名稱:EVE,代碼行數:23,代碼來源:CalendarAPI.java

示例11: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

        Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

        if (clientSecrets.getDetails().getClientId().startsWith("Enter")
                || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
            System.out.println(
                    "Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential "
                            + "into src/main/resources/client_secrets.json");
            System.exit(1);
        }

        FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
        DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
                .build();

        LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

        return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
    }
 
開發者ID:prakamya-mishra,項目名稱:Shield,代碼行數:25,代碼來源:Auth.java

示例12: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 * @return an authorized Credential object.
 * @throws IOException
 */
public static Credential authorize() throws IOException {
    // Load client secrets.
    InputStream in =
        GoogleClassroomClient.class.getResourceAsStream("/client_secret.json");
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("online")
            .build();
    Credential credential = new AuthorizationCodeInstalledApp(
        flow, new LocalServerReceiver()).authorize("user");
    System.out.println(
            "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
    return credential;
}
 
開發者ID:ismartonline,項目名稱:ismartonline,代碼行數:26,代碼來源:GoogleClassroomClient.java

示例13: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的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

示例14: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
/**
 * Creates an authorized Credential object.
 * @return an authorized Credential object.
 * @throws IOException
 */
public static Credential authorize() throws IOException {
    // Load client secrets.
    InputStream in =
        MagisterGoogleCalendarSyncer.class.getResourceAsStream("/client_secret.json");
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();
    Credential credential = new AuthorizationCodeInstalledApp(
        flow, new LocalServerReceiver()).authorize("user");
    System.out.println(
            "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
    return credential;
}
 
開發者ID:skimmet,項目名稱:magister-google-sync,代碼行數:26,代碼來源:MagisterGoogleCalendarSyncer.java

示例15: authorize

import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //導入方法依賴的package包/類
public static Credential authorize(Reader r, Class<?> preferencesNode) throws Exception {

		GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, r);

		if (clientSecrets.getDetails().getClientId().startsWith("Enter")
				|| clientSecrets.getDetails().getClientSecret().startsWith("Enter "))
			throw new RuntimeException(
					"Enter Client ID and Secret from https://code.google.com/apis/console/?api=fusiontables "
							+ "into fusiontables-cmdline-sample/src/main/resources/client_secrets.json");

		GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(getHttpTransport(), JSON_FACTORY,
				clientSecrets, Collections.singleton(FusiontablesScopes.FUSIONTABLES))
						.setDataStoreFactory(getPreferencesStore(preferencesNode)).build();

		return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
	}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:17,代碼來源:Auth.java


注:本文中的com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。