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


Java GmailScopes类代码示例

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


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

示例1: getGmailService

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
private static Gmail getGmailService(String basedir, String appName) throws Exception {

        // 機密情報ファイルのパス
        File DATA_STORE_DIR = new java.io.File(basedir, "gmail-secrets");
        File SECRET_JSON = new java.io.File(DATA_STORE_DIR, "client_secret.json");

        // 準備
        FileDataStoreFactory DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

        // 送信のみ
        List<String> SCOPES = Arrays.asList(GmailScopes.GMAIL_SEND);

        // Credential取得
        try (InputStream in = FileUtils.openInputStream(SECRET_JSON)) {
            GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
            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");

            // Gmailインスタンス生成
            return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName).build();
        }
    }
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:26,代码来源:SmtpManager.java

示例2: main

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
public static void main(String[] args) {	
	
	try {
		System.out.println("----->Sending email message using gmail...");
		GoogleAPIServiceAccountClientData serviceAccountClientID = new GoogleAPIServiceAccountClientData(APP_CODE,
																										 GoogleAPIClientID.of("327116756300-thcjqf1mvrn0geefnu6ef3pe2sm61i2q.apps.googleusercontent.com"),
																									 	 GoogleAPIClientEMailAddress.of("[email protected]account.com"),
																									 	 GoogleAPIClientIDP12KeyPath.loadedFromFileSystem(SERVICE_ACCOUNT_P12_SECRET_PATH),
																									 	 EMail.of("[email protected]"),
																									 	 GmailScopes.all());
		 JavaMailSender mailSender = GMailAPIMailSender.create(serviceAccountClientID);
		
		// [1] - Create a MimeMessagePreparator
		MimeMessagePreparator msgPreparator = _createMimeMessagePreparator(EMail.of("[email protected]"),
																	       EMail.of("[email protected]"),
																	       "A TEST mail message sent using GMail API",
																	       "Just testing GMail API");
		// [2] - Send the message
        mailSender.send(msgPreparator);
		System.out.println("----->Message sent!!");
	} catch(Throwable th) {
		th.printStackTrace(System.out);
	}
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:25,代码来源:GMailAPI2Test.java

示例3: newFlow

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
public static GoogleAuthorizationCodeFlow newFlow(final String userId) throws IOException {
    return new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            getClientCredential(), Collections.singleton(GmailScopes.GMAIL_MODIFY))
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .setApprovalPrompt("force")
            .addRefreshListener(
                    new DataStoreCredentialRefreshListener(userId, DATA_STORE_FACTORY))
            .build();
}
 
开发者ID:MailFred,项目名称:mailfred-appengine,代码行数:11,代码来源:Utils.java

示例4: buildFlow

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
private GoogleAuthorizationCodeFlow buildFlow(GoogleClientSecrets clientSecrets) throws IOException {
    // if the scopes need to change, the user will need to manually delete
    // <TestProperties.TEST_GMAIL_API_FOLDER>/StoredCredential
    final List<String> scopes = Arrays.asList(GmailScopes.GMAIL_READONLY, GmailScopes.GMAIL_MODIFY);
    FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(new File(TestProperties.TEST_GMAIL_API_FOLDER));
    return new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
            .setDataStoreFactory(dataStoreFactory)
            .setAccessType("offline")
            .build();
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:12,代码来源:GmailServiceMaker.java

示例5: main

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
public static void main(String[] args) {	
	try {
		// [1] - Create the transport & json factory
		HttpTransport httpTransport = GoogleAPI.createHttpTransport().noProxy();
		JsonFactory jsonFactory = GoogleAPI.createJsonFactory();
		
		// [2] - Create the google credential
		boolean useServerToken = true;
		GoogleCredential credential = null;
		if (useServerToken) {
			GoogleAPIServiceAccountClientData serviceAccountClientID = new GoogleAPIServiceAccountClientData(APP_CODE,
																											 GoogleAPIClientID.of("327116756300-thcjqf1mvrn0geefnu6ef3pe2sm61i2q.apps.googleusercontent.com"),
																										 	 GoogleAPIClientEMailAddress.of("[email protected]account.com"),
																										 	 GoogleAPIClientIDP12KeyPath.loadedFromFileSystem(SERVICE_ACCOUNT_P12_SECRET_PATH),
																										 	 EMail.of("[email protected]"),
																										 	 GmailScopes.all());
			credential = GoogleAPI.createCredentialForServiceAccount(httpTransport,
														   			 jsonFactory,
														   			 serviceAccountClientID);
		} else {				
			credential = GoogleAPI.createCredentialForNativeApp(httpTransport,
														   		jsonFactory,
														   		new GoogleAPINativeApplicationClientData(APP_CODE,
														   												 GoogleAPIClientID.of("327116756300-fd4u232iat8srb3gumlfsqdn244ksc8h.apps.googleusercontent.com"),
														   											     GoogleAPIClientIDJsonKeyPath.loadedFromFileSystem(NATIVE_APP_CLIENT_SECRET_PATH),
														   											     GmailScopes.all()));
		}
		
		// [3] - Create the gmail service
		Gmail gmailService = GoogleAPI.createGmailService(httpTransport,
												 		  jsonFactory,
												 		  APP_CODE,
												 		  credential);
		
		// [4] - Send a test messag
		_sendMessage(gmailService,
					 USER,
					 _createEmail("[email protected]","[email protected]",
							 	  "Test OK server side!",
							 	  "I got it!! It works!"));
		
	} catch(Throwable th) {
		th.printStackTrace(System.out);
	}
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:46,代码来源:GMailAPITest.java

示例6: get

import com.google.api.services.gmail.GmailScopes; //导入依赖的package包/类
public Credential get() {
  try {
    GoogleClientSecrets clientSecrets = loadGoogleClientSecrets(jsonFactory);

    DataStore<StoredCredential> dataStore = getStoredCredentialDataStore();

    // Allow user to authorize via url.
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(
            httpTransport,
            jsonFactory,
            clientSecrets,
            ImmutableList.of(
                GmailScopes.GMAIL_MODIFY,
                GmailScopes.GMAIL_READONLY))
            .setCredentialDataStore(dataStore)
            .setAccessType("offline")
            .setApprovalPrompt("auto")
            .build();

    // First, see if we have a stored credential for the user.
    Credential credential = flow.loadCredential(user.getEmailAddress());

    // If we don't, prompt them to get one.
    if (credential == null) {
      String url = flow.newAuthorizationUrl()
          .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI)
          .build();
      System.out.println("Please open the following URL in your browser then "
          + "type the authorization code:\n" + url);

      // Read code entered by user.
      System.out.print("Code: ");
      System.out.flush();
      BufferedReader br = new BufferedReader(
          new InputStreamReader(System.in));
      String code = br.readLine();

      // Generate Credential using retrieved code.
      GoogleTokenResponse response = flow.newTokenRequest(code)
          .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI)
          .execute();

      credential =
          flow.createAndStoreCredential(response, user.getEmailAddress());
    }

    Gmail gmail = new Gmail.Builder(httpTransport, jsonFactory, credential)
        .setApplicationName(GmailServiceModule.APP_NAME)
        .build();

    Profile profile = gmail.users()
        .getProfile(user.getEmailAddress())
        .execute();

    System.out.println(profile.toPrettyString());
    return credential;
  } catch (IOException exception) {
    throw new RuntimeException(exception);
  }
}
 
开发者ID:google,项目名称:mail-importer,代码行数:62,代码来源:Authorizer.java


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