Java 有没有办法让谷歌联系人在没有特定帐户设置的情况下使用密码和用户名(电子邮件)?

Java 有没有办法让谷歌联系人在没有特定帐户设置的情况下使用密码和用户名(电子邮件)?,java,authorization,gdata,Java,Authorization,Gdata,我正在尝试使用gdata获取特定用户的google联系人。该操作将在控制台应用程序中执行。拥有用户名电子邮件和密码,我可以检索所需的数据,以防启用未经检查的应用程序的帐户级别访问,因为我知道我正在使用ClientLogin。如果应用程序特定的密码设置为帐户级别,我也可以使用它。 我知道我可以使用Oauth进行授权,而不使用用户ID密码,但这对我来说几乎不起作用,因为据我所知,每次使用都必须为本机应用程序生成客户端ID,包括客户端ID、客户端机密和重定向URI。如果我不正确,请纠正我 我使用的代码

我正在尝试使用gdata获取特定用户的google联系人。该操作将在控制台应用程序中执行。拥有用户名电子邮件和密码,我可以检索所需的数据,以防启用未经检查的应用程序的帐户级别访问,因为我知道我正在使用ClientLogin。如果应用程序特定的密码设置为帐户级别,我也可以使用它。 我知道我可以使用Oauth进行授权,而不使用用户ID密码,但这对我来说几乎不起作用,因为据我所知,每次使用都必须为本机应用程序生成客户端ID,包括客户端ID、客户端机密和重定向URI。如果我不正确,请纠正我

我使用的代码是:

ContactsService contactsService = new ContactsService("projectName");
contactsService.setUserCredentials(email, password);
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl);
myQuery.setMaxResults(100);
ContactFeed resultFeed = contactsService.getFeed(myQuery, ContactFeed.class);

是否有任何方法可以从帐户中获取所有联系人,而不依赖于帐户设置,使用userIdemail和passowrd?打开浏览器并让用户进行授权或类似的操作也可能会起作用

最终设法让它起作用 以防有人面临同样的问题

在Google中创建一个帐户,为本机应用程序生成json文件客户端ID,包括客户端ID、客户端机密和重定向 将json文件放入应用程序中 以与以下类似的方式创建凭据

public class AuthorizationHelper {

    public static Credential authorize() throws Exception {
        java.io.File DATA_STORE_DIR =
                new java.io.File("permissionsFile", "PermissionsFolder");
        JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        // load client secrets
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
                new InputStreamReader(new FileInputStream("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=plus "
                            + "into plus-cmdline-sample/src/main/resources/client_secrets.json");
            System.exit(1);
        }
        // set up authorization code flow
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                httpTransport, JSON_FACTORY, clientSecrets,
                Collections.singleton("https://www.google.com/m8/feeds/contacts/default/full")).setDataStoreFactory(
                dataStoreFactory).build();
        // authorize
        return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("googleAccount");
    }
}
其中permissionsFile和permissionsFolder是临时存储您尝试登录的帐户权限的文件和文件夹 googleAccount-您创建的帐户在没有@gmail.com的情况下使用

那就做吧

myService.setOAuth2Credentials(AuthorizationHelper.authorize());
并删除

contactsService.setUserCredentials(email, password);
因为您不需要在代码中输入登录名和密码

您将被重定向到浏览器中的登录页面,并被要求输入login和passord

希望这对某人有帮助

谢谢

埃夫格尼