java - 将 Web 应用程序与 Quickbooks 集成时出现 Oauth 授权问题

标签 java oauth quickbooks intuit-partner-platform quickbooks-online

我正在尝试将我的网络应用程序与 QuickBooks 集成,我实现了连接到 QuickBooks 按钮,直觉也授予了该应用程序的权限。

enter image description here

但是,我收到我们在处理您的请求时遇到问题问题。 enter image description here

可能是什么问题?我的 call_back 网址也没有得到任何响应。

我使用了 Intuit 示例应用程序中的代码。

public static String REQUEST_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_request_token";
public static String ACCESS_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_access_token";
public static String AUTHORIZE_URL = "https://appcenter.intuit.com/Connect/Begin";
public static String OAUTH_CONSUMER_KEY = "qyprdFHGmJjBj1jDH05Jen95Tu3PyW";
public static String OAUTH_CONSUMER_SECRET = "OMFkKCPRBQKrMoyaLg9mFYTM26kpJg8LPthbNzTB";
public static String OAUTH_CALLBACK_URL = "http://office.technology.com:8081/delegate/intuit/";

public Map<String, String> getRequestTokenSignPost() {

    String authURL = null;

    OAuthProvider provider = createProvider();

    String consumerkey = OAUTH_CONSUMER_KEY;
    String consumersecret = OAUTH_CONSUMER_SECRET;

    LOG.info("Inside getRequestToken, Consumer Key and Secret: " + consumerkey + " " + consumersecret);
    String callback_url = OAUTH_CALLBACK_URL;
    LOG.info("callback URL: " + callback_url);

    OAuthConsumer ouathconsumer = new DefaultOAuthConsumer(consumerkey, consumersecret);

    try {
        HttpParameters additionalParams = new HttpParameters();
        additionalParams.put("oauth_callback", URLEncoder.encode(callback_url, "UTF-8"));
        ouathconsumer.setAdditionalParameters(additionalParams);
    } catch (UnsupportedEncodingException e) {
        LOG.error(e.getLocalizedMessage());
    }

    String requestret = "";
    String requestToken = "";
    String requestTokenSecret = "";

    try {
        String signedRequestTokenUrl = ouathconsumer.sign(REQUEST_TOKEN_URL);
        LOG.info("signedRequestTokenUrl: " + signedRequestTokenUrl);

        URL url;

        url = new URL(signedRequestTokenUrl);

        HttpURLConnection httpconnection = (HttpURLConnection) url.openConnection();
        httpconnection.setRequestMethod("GET");
        httpconnection.setRequestProperty("Content-type", "application/xml");
        httpconnection.setRequestProperty("Content-Length", "0");
        if (httpconnection != null) {
            BufferedReader rd = new BufferedReader(new InputStreamReader(httpconnection.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = rd.readLine()) != null) {
                sb.append(line);

            }
            rd.close();
            requestret = sb.toString();
        }
        String[] requestTokenSections = requestret.split("&");

        for (int i = 0; i < requestTokenSections.length; i++) {
            String[] currentElements = requestTokenSections[i].split("=");

            if (currentElements[0].equalsIgnoreCase("oauth_token")) {
                requestToken = currentElements[1];
            } else if (currentElements[0].equalsIgnoreCase("oauth_token_secret")) {
                requestTokenSecret = currentElements[1];
            }
        }

        Map<String, String> requesttokenmap = new HashMap<String, String>();

        try {
            authURL = provider.retrieveRequestToken(ouathconsumer, callback_url);
        } catch (OAuthNotAuthorizedException e) {
            LOG.error(e.getLocalizedMessage());
        }
        ouathconsumer.setTokenWithSecret(ouathconsumer.getToken(), ouathconsumer.getTokenSecret());

        requesttokenmap.put("requestToken", requestToken);
        requesttokenmap.put("requestTokenSecret", requestTokenSecret);
        requesttokenmap.put("authURL", authURL);
        return requesttokenmap;

    } catch (OAuthMessageSignerException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (OAuthExpectationFailedException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (OAuthCommunicationException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (MalformedURLException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (IOException e) {
        LOG.error(e.getLocalizedMessage());
    }
    LOG.info("Error: Failed to get request token.");
    return null;

}

public static OAuthProvider createProvider() {
    OAuthProvider provider =
            new DefaultOAuthProvider(OauthHelper.REQUEST_TOKEN_URL, OauthHelper.ACCESS_TOKEN_URL, OauthHelper.AUTHORIZE_URL);

    return provider;
}

public String getAuthorizeURL(String requestToken, String requestTokenSecret) {

    String authorizeURL = "";
    try {
        authorizeURL = AUTHORIZE_URL + "?oauth_token=" + requestToken;
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage());
    }
    LOG.info("Authorize URL: " + authorizeURL);
    return authorizeURL;
}

我什至获得了请求 token :

signedRequestTokenUrl: https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=EHKmrR%2BV%2ByF4WRcBmpkdBeYEfuE%3D&oauth_callback=http%253Aoffice.technology.com%253A8081%252Fdelegate%252Fintuit&oauth_consumer_key=qyprdFHGaJjBj1jDH05Jen95Tu3PyW&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1390538706&oauth_nonce=-4612911034475731539
requestret: oauth_token_secret=XkXjGlS6bnFvOWYthCoew54W4ILcdMWQ3jaOMCQQ&oauth_callback_confirmed=true&oauth_token=qyprdRyUiXzU0QLLavn3L3TtdqvYts5CZyomkSk8miZDfB8Y

最佳答案

这个:

public static String OAUTH_CALLBACK_URL = "http:office.technology.com:8081/delegate/intuit/";

不是一个有效的 URL,但它必须是。修复您的网址。

关于java - 将 Web 应用程序与 Quickbooks 集成时出现 Oauth 授权问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21305820/

相关文章:

php - 在现有发票中添加新发票行不起作用

java - 计算值太大而无法求幂的马尔可夫链概率

java - Tomcat 会自动维护一个 MySql 连接池吗?

java - 如何将我在 tomcat 8080 端口上运行的应用程序 URL 重定向到域 www.xyz.com

python - 如何在 GitHub 上托管的 Python 脚本中保密开发人员 key

Android:Google SSO - OAuth 或 AccountManager?或两者?

java - Quickbooks 在线公司MetaData java

api - Quickbooks 中发生事件后触发 API 调用?

java - 是否有任何关于事务性文件I/O、Java 语言的开源工具或框架?

php - Twitter oAuth 请求 token 无效