Office365 生成具有Office 365邮件错误代码的守护程序或服务应用程序

Office365 生成具有Office 365邮件错误代码的守护程序或服务应用程序,office365,Office365,我在跟踪 我正在用Java编写生成令牌的程序。我从git for java获取了AADL库 我使用以下java代码,而不是.net博客中建议的代码, 字符串标记=null; 字符串tenant=“我的租户” 字符串权限=”https://login.windows.net/“+租户+”/oauth2/authorize”; ExecutorService=null; 服务=Executors.newFixedThreadPool(1); 试一试{ AuthenticationContext A

我在跟踪

我正在用Java编写生成令牌的程序。我从git for java获取了AADL库

我使用以下java代码,而不是.net博客中建议的代码, 字符串标记=null; 字符串tenant=“我的租户”

字符串权限=”https://login.windows.net/“+租户+”/oauth2/authorize”;
ExecutorService=null;
服务=Executors.newFixedThreadPool(1);
试一试{
AuthenticationContext AuthenticationContext=新的AuthenticationContext(authority、false、service);
字符串certfile=“filapath/mycert.pfx”;
InputStream pkcs12Certificate=新文件InputStream(certfile);
AsymmetricKeyCredential credential=AsymmetricKeyCredential.create(“客户端id”,PKCS12证书,“密码”);
System.out.println(“X509很好!”);
Future=authenticationContext.acquireToken(“https://outlook.office365.com“,凭证,空);
System.out.println(“收到的令牌”+future.get().getAccessToken());
token=future.get().getAccessToken();
}捕获(格式错误){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
但是,当我使用在这个过程中获取的令牌访问邮件RESTAPI时,它给了我HTTP401错误。 我在指定X509证书密钥时是否出错??
还是别的什么?

问题现在解决了!我犯了一个愚蠢的错误。你犯了什么错误?我也有“未经授权”的问题你好robertmiles3,我通过调用future.get().getAccessToken()收到了正确的令牌。但是,为了获取电子邮件数据,我调用了HttpURLConnection con=(HttpURLConnection)obj.openConnection();con.setRequestMethod(“GET”);con.setRequestProperty(“接受”、“应用程序/json”);con.setRequestProperty(“授权”,令牌);,授权标头的设置应类似于,con.setRequestProperty(“授权”、“承载者”+令牌);。然后成功了!我可以获取电子邮件和日历详细信息。你如何上传证书?@WowBow我问题中的链接包含了所有需要的步骤。微软似乎已经删除了这个链接。如果我能在其他地方找到类似的内容,我会尝试搜索。
    String authority = "https://login.windows.net/"+tenant+"/oauth2/authorize";
    ExecutorService service = null;
    service=Executors.newFixedThreadPool(1);
    try {
        AuthenticationContext authenticationContext =  new AuthenticationContext(authority, false, service);
        String certfile = "filapath/mycert.pfx";
        InputStream pkcs12Certificate=new FileInputStream(certfile);



        AsymmetricKeyCredential credential = AsymmetricKeyCredential.create("client_id", pkcs12Certificate,"password");
        System.out.println("X509 is fine!");

        Future<AuthenticationResult> future=authenticationContext.acquireToken("https://outlook.office365.com", credential, null);
        System.out.println("Token Received"+future.get().getAccessToken());
        token=future.get().getAccessToken();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }