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


Java Userinfoplus类代码示例

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


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

示例1: initializeUserInfo

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
private void initializeUserInfo(
    Userinfoplus userInfo, @Nullable final IGoogleLoginCompletedCallback loginCompletedCallback) {
  if (userInfo == null) {
    name = null;
    image = null;
  } else {
    name = userInfo.getName();
    GoogleLoginUtils.provideUserPicture(
        userInfo,
        newImage -> {
          image = newImage;
          if (loginCompletedCallback != null) {
            loginCompletedCallback.onLoginCompleted();
          }
        });
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:18,代码来源:CredentialedUser.java

示例2: provideUserPicture

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
/**
 * Gets the profile picture that corresponds to the {@code userInfo} and sets it on the provided
 * {@code pictureCallback}.
 *
 * @param userInfo the class to be parsed
 * @param pictureCallback the user image will be set on this callback
 */
@SuppressWarnings("FutureReturnValueIgnored")
public static void provideUserPicture(Userinfoplus userInfo, Consumer<Image> pictureCallback) {
  // set the size of the image before it is served
  String urlString = userInfo.getPicture() + "?sz=" + DEFAULT_PICTURE_SIZE;
  URL url;
  try {
    url = new URL(urlString);
  } catch (MalformedURLException ex) {
    LOG.warn(String.format("The picture URL: %s,  is not a valid URL string.", urlString), ex);
    return;
  }

  final URL newUrl = url;

  ApplicationManager.getApplication()
      .executeOnPooledThread(
          () -> {
            try {
              pictureCallback.accept(ImageIO.read(newUrl));
            } catch (IOException exception) {
              pictureCallback.accept(null);
            }
          });
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:32,代码来源:GoogleLoginUtils.java

示例3: getAccountInfo

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
/**
 * Requests the user info for the given account. This requires previous
 * authorization from the user, so this might start the process.
 *
 * @param accountId
 *            The id of the account to get the user info.
 * @return The user info bean.
 * @throws IOException If the account cannot be accessed.
 */
GoogleAccount getAccountInfo(String accountId) throws IOException {
    Credential credential = impl_getStoredCredential(accountId);
    if (credential == null) {
        throw new UnsupportedOperationException("The account has not been authorized yet!");
    }
    Userinfoplus info = impl_requestUserInfo(credential);
    GoogleAccount account = new GoogleAccount();
    account.setId(accountId);
    account.setName(info.getName());
    return account;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:21,代码来源:GoogleConnector.java

示例4: TestApp

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
public TestApp() {
	try
	{
		HttpTransport httpTransport = new NetHttpTransport();             
		JacksonFactory jsonFactory = new JacksonFactory();
		//ComputeCredential credential = new ComputeCredential.Builder(httpTransport, jsonFactory).build();	
		GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);				            
		if (credential.createScopedRequired())
		    credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));           				            
		Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
		            .setApplicationName("oauth client")   
		            .build();				            
		Userinfoplus ui = service.userinfo().get().execute();
		System.out.println(ui.getEmail());



         // Using Google Cloud APIs
	  Storage  storage_service = StorageOptions.defaultInstance().service();
       
         Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
         while (bucketIterator.hasNext()) {
           System.out.println(bucketIterator.next());
         }	

	} 
	catch (Exception ex) {
		System.out.println("Error:  " + ex);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:31,代码来源:TestApp.java

示例5: doGet

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	resp.setContentType("text/plain");
	resp.getWriter().println("Hello, world");
			
	HttpTransport httpTransport = new UrlFetchTransport();        
	JacksonFactory jsonFactory = new JacksonFactory();

	/*
	AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();    
	AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));         
	GoogleCredential credential = new GoogleCredential.Builder()
		.setTransport(httpTransport)
		.setJsonFactory(jsonFactory).build();
    credential.setAccessToken(accessToken.getAccessToken());
	*/

	GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);    
	if (credential.createScopedRequired())
	    credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));           

	Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
	    .setApplicationName("oauth client").build();

	Userinfoplus ui = service.userinfo().get().execute(); 
	resp.getWriter().println(ui.getEmail());
    

         // Using Google Cloud APIs
	  Storage  storage_service = StorageOptions.defaultInstance().service();
       
         Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
         while (bucketIterator.hasNext()) {
           System.out.println(bucketIterator.next());
         }		

}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:38,代码来源:TestServlet.java

示例6: TestApp

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
public TestApp() {
	try
	{

		HttpTransport httpTransport = new NetHttpTransport();
		JacksonFactory jsonFactory = new JacksonFactory();

		GoogleClientSecrets clientSecrets =  new GoogleClientSecrets();
		GoogleClientSecrets.Details det = new GoogleClientSecrets.Details();
		det.setClientId("YOUR_CLIENT_ID");
		det.setClientSecret("YOUR_CLIENT_SECRET");
		det.setRedirectUris(Arrays.asList("urn:ietf:wg:oauth:2.0:oob"));
		clientSecrets.setInstalled(det);

		GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
		    httpTransport, jsonFactory, clientSecrets,
		    Arrays.asList(Oauth2Scopes.USERINFO_EMAIL)).build();
		Credential credential = new AuthorizationCodeInstalledApp(flow,
		    new LocalServerReceiver()).authorize("user");

		Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
		    .setApplicationName("oauth client").build();

		Userinfoplus ui = service.userinfo().get().execute();
		System.out.println(ui.getEmail());
	} 
	catch (Exception ex) {
		System.out.println("Error:  " + ex);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:31,代码来源:TestApp.java

示例7: getUserInfo

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
/** Sets the user info on the callback. */
@SuppressWarnings("FutureReturnValueIgnored")
public static void getUserInfo(
    @NotNull final Credential credential, final IUserPropertyCallback<Userinfoplus> callback) {
  final Oauth2 userInfoService =
      new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
          .setApplicationName(
              ServiceManager.getService(AccountPluginInfoService.class).getUserAgent())
          .build();

  ApplicationManager.getApplication()
      .executeOnPooledThread(
          () -> {
            Userinfoplus userInfo = null;
            try {
              userInfo = userInfoService.userinfo().get().execute();
            } catch (IOException ex) {
              // The core IDE functionality still works, so this does
              // not affect anything right now. The user will receive
              // error messages when they attempt to do something that
              // requires a logged in state.
              LOG.warn("Error retrieving user information.", ex);
            }

            if (userInfo != null && userInfo.getId() != null) {
              callback.setProperty(userInfo);
            } else {
              callback.setProperty(null);
            }
          });
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:32,代码来源:GoogleLoginUtils.java

示例8: loginWithGoogle

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
@JsonRequest
@Path("/login_with_google")
public Response<WebUser> loginWithGoogle(@ApiParam("access_token") String accessToken) {
    GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
    Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(),
            new JacksonFactory(), credential).setApplicationName("Oauth2").build();
    Userinfoplus userinfo;
    try {
        userinfo = oauth2.userinfo().get().execute();

        if (!userinfo.getVerifiedEmail()) {
            throw new RakamException("The Google email must be verified", BAD_REQUEST);
        }

        Optional<WebUser> userByEmail = service.getUserByEmail(userinfo.getEmail());
        WebUser user = userByEmail.orElseGet(() ->
                service.createUser(userinfo.getEmail(),
                        null, userinfo.getGivenName(),
                        userinfo.getGender(),
                        userinfo.getLocale(),
                        userinfo.getId(), false));
        return getLoginResponseForUser(encryptionConfig.getSecretKey(), user, config.getCookieDuration());
    } catch (IOException e) {
        LOGGER.error(e);
        throw new RakamException("Unable to login", INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:28,代码来源:WebUserHttpService.java

示例9: impl_requestUserInfo

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
private Userinfoplus impl_requestUserInfo(Credential credentials) throws IOException {
    Oauth2 userInfoService = new Oauth2.Builder(httpTransport, jsonFactory, credentials).setApplicationName(APPLICATION_NAME).build();
    return userInfoService.userinfo().get().execute();
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:5,代码来源:GoogleConnector.java

示例10: TestApp

import com.google.api.services.oauth2.model.Userinfoplus; //导入依赖的package包/类
public TestApp() {
	try
	{
		HttpTransport httpTransport = new NetHttpTransport();             
		JacksonFactory jsonFactory = new JacksonFactory();

           // unset GOOGLE_APPLICATION_CREDENTIALS
           //String SERVICE_ACCOUNT_JSON_FILE = "YOUR_SERVICE_ACCOUNT_JSON_FILE.json";
           //FileInputStream inputStream = new FileInputStream(new File(SERVICE_ACCOUNT_JSON_FILE));
           //GoogleCredential credential = GoogleCredential.fromStream(inputStream, httpTransport, jsonFactory);

		// to use application default credentials and a JSON file, set the environment variable first:
           // export GOOGLE_APPLICATION_CREDENTIALS=YOUR_SERVICE_ACCOUNT_JSON_FILE.json        
           GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);

           if (credential.createScopedRequired())
               credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));

		Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
		            .setApplicationName("oauth client")   
		            .build();				            
		Userinfoplus ui = service.userinfo().get().execute();
		System.out.println(ui.getEmail());


         // Using Google Cloud APIs with service account file
	  // You can also just export an export GOOGLE_APPLICATION_CREDENTIALS and use StorageOptions.defaultInstance().service()
	  // see: https://github.com/google/google-auth-library-java#google-auth-library-oauth2-http
	  /*
	  Storage storage_service = StorageOptions.newBuilder()
		.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream("/path/to/your/certificate.json")))
		.build()
		.getService();			
	  */

         // Using Google Cloud APIs

	  Storage  storage_service = StorageOptions.defaultInstance().service();
       
         Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
         while (bucketIterator.hasNext()) {
           System.out.println(bucketIterator.next());
         }		
	} 
	catch (Exception ex) {
		System.out.println("Error:  " + ex);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:49,代码来源:TestApp.java


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