简体   繁体   English

用Java调用HealthVault GetThings方法

[英]Calling the HealthVault GetThings method in Java

I'm trying to use the Java HealthVault API to make a call to the GetThings method in "offline" mode (meaning, the user doesn't have to login) to retrieve all "File" type items. 我正在尝试使用Java HealthVault API以“脱机”模式调用GetThings方法(这意味着用户不必登录)以检索所有“文件”类型的项。 From what I understand, all you need to make an offline request is the Persion ID and Record ID of the user's account. 据我了解,发出离线请求所需要做的就是用户帐户的Persion ID和Record ID。 However, even though I'm adding these to the request, the method call doesn't work. 但是,即使我将这些添加到请求中,方法调用也不起作用。 It returns the error code "67" in the response, which, according to a static variable in the API, stands for "invalid person or group ID". 它在响应中返回错误代码“ 67”,根据API中的静态变量,该错误代码表示“无效的人员或组ID”。

I've double checked the Person ID and Record IDs and they are indeed correct. 我已经仔细检查了人员ID和记录ID,它们确实是正确的。 Making the same request in "online" mode (ie when including a user-auth-token) works perfectly fine. 在“在线”模式下(即,当包含用户身份验证令牌时)发出相同的请求非常正常。 My application is configured to allow offline access to all "File" item types, so it couldn't be an access issue. 我的应用程序配置为允许脱机访问所有“文件”项类型,因此它不是访问问题。

I've replaced the real Person ID and Record IDs with fake ones in the below code samples for security reasons: 出于安全原因,在下面的代码示例中,我用伪造的ID替换了真实的Person ID和Record ID:

Here's my Java code: 这是我的Java代码:

StringBuilder requestXml = new StringBuilder();
requestXml.append("<info><group>");
requestXml.append("<filter><type-id>bd0403c5-4ae2-4b0e-a8db-1888678e4528</type-id></filter>");
requestXml.append("<format><section>core</section><section>otherdata</section><xml/></format>");
requestXml.append("</group></info>");

Request request = new Request();
request.setMethodName("GetThings");
request.setOfflineUserId("e2f925e7-2748-4d88-bz48-32036dc10020");
request.setRecordId("73ab2792-5481-43eb-837c-67d1e3337300");
request.setInfo(requestXml.toString());

Connection connection = ConnectionFactory.getConnection();
HVAccessor accessor = new HVAccessor();
accessor.send(request, connection);

The XML request it generates: 它生成的XML请求:

<wc-request:request xmlns:wc-request="urn:com.microsoft.wc.request">
    <auth>
        <hmac-data algName="HMACSHA1">5WdiBnTvxsNbVHg134ggIETlJNE=</hmac-data>
    </auth>
    <header>
        <method>GetThings</method>
        <method-version>1</method-version>
        <record-id>73ab2792-5481-43eb-837c-67d1e3337300</record-id>
        <auth-session>
            <auth-token>ASAAAJQ1R50J8HpMshAjeHkjh/habVgM17BjSBuA/GmbJPV9A9d63mramakSZxf+ZHZh+7xWllTWGhAijBvxhNxauzBLci1IWWh+JDbGQZabnWbG7YH28ZP+FQuRPNP4T8O1NTNCFNETao0ly+UuPjWEZWCV5cCPX7GjaEJ4BMAFv4vAOEwIOe63VWntfzH9r3Rz0VnHAhb400iqs1XxlJrRbgXdNRdg</auth-token>
            <offline-person-info>
                <offline-person-id>e2f925e7-2748-4d88-bz48-32036dc10020</offline-person-id>
            </offline-person-info>
        </auth-session>
        <language>en</language>
        <country>US</country>
        <msg-time>2009-10-21T12:37:51.706-04:00</msg-time>
        <msg-ttl>180000</msg-ttl>
        <version>0.0.0.1</version>
        <info-hash>
            <hash-data algName="SHA1">oAZVXLGAUMfuVPrqjqb98yCb4/c=</hash-data>
        </info-hash>
    </header>
    <info>
        <group>
            <filter>
                <type-id>bd0403c5-4ae2-4b0e-a8db-1888678e4528</type-id>
            </filter>
            <format>
                <section>core</section>
                <section>otherdata</section>
                <xml />
            </format>
        </group>
    </info>
</wc-request:request>

The XML response I get back: 我得到的XML响应:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <status>
        <code>67</code>
        <error>
            <message>Exception of type
                'Microsoft.Health.Platform.WildcatStatusException' was thrown.</message>
        </error>
    </status>
</response>

Thank you so much for your help. 非常感谢你的帮助。 :) :)

Some other guy resolved the error by doing. 其他人通过执行解决了该错误。 You already tried this? 您已经尝试过了吗?

I got the error cleared up. I re-imported the certificate (found in the cert
folder) through the Healthvault Application Manager, cleared up the offline.txt
file and re-ran the application.

Turns out the problem was that my Person and Record IDs actually were incorrect. 原来,问题是,我个人并记录ID实际上不正确的。 I was using the ones I got while connected to the sample application, as opposed to my own application. 我使用的是连接到示例应用程序时获得的程序,而不是我自己的应用程序。 I didn't know they changed across applications. 我不知道它们在应用程序之间发生了变化。 After making a call to GetPersonInfo from my own application, I was able to get the correct Person and Record IDs. 从我自己的应用程序调用GetPersonInfo之后,我能够获得正确的Person和Record ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM