java - Quickbooks 身份验证错误 - Java SDK Quickbooks v3.0

标签 java web-services rest quickbooks

这是我第一次尝试使用Quickbooks API。为了开始使用它,我想尝试一些 API 调用。

我已经在 Quickbooks 上创建了帐户并获得了以下凭据 -

consumerKey
consumerSecret
accessToken
accessTokenSecret
appToken
companyId

已下载IPP java sdk for QuickBooks v3.0从下载的包中,我当前正在使用以下 jar 文件 -

ipp-v3-java-devkit-2.3.2-jar-with-dependencies.jar
ipp-java-qbapihelper-1.2.0-jar-with-dependencies.jar

这是我正在执行的代码。

import com.intuit.ipp.core.Context;
import com.intuit.ipp.core.ServiceType;
import com.intuit.ipp.data.Customer;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.security.OAuthAuthorizer;
import com.intuit.ipp.services.DataService;

 public class TestQuickBooks {
  public static void main(String[] args) 
   throws FMSException 
   {
    // following credentials are replaced with my original credential
    // when executing the code 
    String consumerKey = "...";
    String consumerSecret = "...";
    String accessToken = "...";
    String accessTokenSecret = "...";
    String appToken = "...";
    String companyId = "...";

    try {
      OAuthAuthorizer oauth = new OAuthAuthorizer(consumerKey,
                                                  consumerSecret,
                                                  accessToken,
                                                  accessTokenSecret);
      Context context = new Context(oauth,
                                    appToken,
                                    ServiceType.QBO,
                                    companyId);
      DataService service = new DataService(context);

      Customer customer1 = new Customer();
      customer1.setDisplayName("ABCD");

      // this is the line which is throwing exception
      Customer resultCustomer = service.add(customer1);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

在此处复制异常消息 --

com.intuit.ipp.exception.AuthenticationException: ERROR CODE:3200, ERROR MESSAGE:message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401, ERROR DETAIL:null  

我正在检查 Quickbooks 文档,但无法找出导致此身份验证异常的原因。至于凭据,我已经仔细检查过,这些都是正确的。

我发现 Quickbooks 有一个 API playground但也没有运气。

尝试了此 API 调用 -

https://appcenter.intuit.com/api/v1/PingSecure

我提供了我的凭据并将格式指定为 JSON,并且没有 url 参数。 它返回以下消息 -

{
    "ErrorMessage": "This API requires Authorization.",
    "ErrorCode": 22,
    "ServerTime": "/Date(1412166272838)/"
}

我希望 api Playground 不应该返回身份验证错误,因为我的凭据是正确的。然而,我可以看到 api 调用的唯一方法是当我登录 API explorer

我不太确定这里缺少什么 - 无法从 API Playground 进行 API 调用,也无法以编程方式使用 Java SDK。

最佳答案

请添加以下属性:

Config.setProperty(Config.BASE_URL_QBO,"https://sandboxquickbooks.api.intuit.com/v3/company");

之前:

DataService service = new DataService(context);

这对我有用。

关于java - Quickbooks 身份验证错误 - Java SDK Quickbooks v3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123728/

相关文章:

java - 什么是NullPointerException,我该如何解决?

java - 在 JAVA 中从 WADL URL 生成休息客户端

database - RESTFul 架构中的唯一约束

javascript - 将服务器 API 作为 brunch 应用程序的一部分构建是一种不好的做法吗?

java - 如何在 BadRequestException 中包含消息?

使用 https 的 Java Jersey RESTful Web 服务

java - React + Spring Boot上传文件和表单数据

java - 如何修复凯撒密码程序中的 "char cannot be converted to java.lang.String"

java - JButton 上的 ActionPerformed 调用不止一次?

java - 大端字节序的位掩码