3

こんにちは、私は Java で作業しており、Provisionin api を使用したドメイン内のすべてのユーザーを取得しようとしました.........うまく機能していますが、私の考えは、2-legged OAuth を使用して取得することですドメインからのユーザー それは可能ですか? URLを指定する方法がわかりません助けてくださいそして、私は次のプログラムを試しました

    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 authorization header としてエラーを返す

4

1 に答える 1

1
    // 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 の 2-Legged OAuth は、ユーザーが不要であるという意味で特別です。必要ありませんxoauth_id=123@xxx.com。管理者はクライアントを承認できます https://www.google.com/a/cpanel/<your domain>/ManageOauthClients

于 2011-04-26T00:15:37.953 に答える