使用java配置Api [英] Provisioning Api using java
问题描述
您好我正在使用java并尝试检索域中的所有用户,因为我使用了Provisionin api ............它的工作正常但是我的想法是使用2-legged OAuth从域中检索用户是否可能?我不知道如何指定URL请帮助我我尝试了以下程序
Hi i'm working in java and tried to retrieve all the user in the domain for that i used Provisionin api............ Its working good But my idea is to Use 2-legged OAuth to retrieve the users from the domain Is it Possible? I don't how to specify the URL please Help me And i tried the following the program
final String CONSUMER_KEY = "example.com";
final String CONSUMER_SECRET = "12345678122154154df9";
final String DOMAIN = "example.com";
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
URL feedUrl = new URL("https://apps-apis.google.com/a/feeds/" + DOMAIN +
"/user/2.0/?xoauth_id=123@example.com");
userService = new UserService("Myapplication");
userService.setOAuthCredentials(oauthParameters, signer);
userService.useSsl();
UserFeed allUsers = new UserFeed();
UserFeed allpage;
Link nextLink;
do {
allpage = userService.getFeed(feedUrl, UserFeed.class);
allUsers.getEntries().addAll(allpage.getEntries());
nextLink = allpage.getLink(Link.Rel.NEXT, Link.Type.ATOM);
if (nextLink != null) {
feedUrl = new URL(nextLink.getHref());
}
}while (nextLink != null);
return allUsers;
}
它以com.google.gdata.util.AuthenticationException:Unknown来回避错误授权标题
Its returing the error as com.google.gdata.util.AuthenticationException: Unknown authorization header
推荐答案
// use real values.
final String CONSUMER_KEY = "example.com";
final String CONSUMER_SECRET = "secret-here";
final String DOMAIN = "domain.com";
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
URL feedUrl = new URL("https://apps-apis.google.com/a/feeds/" + DOMAIN + "/user/2.0");
UserService service = new UserService("ProvisiongApiClient");
service.setOAuthCredentials(oauthParameters, signer);
service.useSsl();
UserFeed resultFeed = service.getFeed(feedUrl, UserFeed.class);
for (UserEntry entry : resultFeed.getEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
Google Apps API的双腿OAuth在某种意义上是特殊的用户少。您不需要 xoauth_id=123@xxx.com
。管理员可以从 https://www.google.com/a/cpanel/<您的域> / ManageOauthClients
2-Legged OAuth for Google Apps APIs is special in the sense that it is user-less. You don't need xoauth_id=123@xxx.com
. An admin can authorize clients from https://www.google.com/a/cpanel/<your domain>/ManageOauthClients
这篇关于使用java配置Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!