E * Trade OAuth API(Java)出现问题 [英] Having Issues with the E*Trade OAuth API (Java)

查看:114
本文介绍了E * Trade OAuth API(Java)出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序,该程序将使用E * Trade API在沙盒环境中交易股票.我正在使用他们的示例代码作为准则,目前.getAuthorizeURL()方法遇到问题.它说它对于String类型是未定义的,但是,在反编译OAuth jar之后,我陷入了如何解决此问题的麻烦之中.

I'm trying to code a program that will trade stocks in a sandbox environment with the E*Trade API. I am using their sample code as a guideline and currently am getting an issue with the .getAuthorizeURL() method. It says that it is undefined for type String however, after decompiling the OAuth jar I am stuck in a rut about how to solve this issue.

import com.etrade.etws.account.Account;
import com.etrade.etws.account.AccountListResponse;
import com.etrade.etws.oauth.sdk.client.IOAuthClient;
import com.etrade.etws.oauth.sdk.client.OAuthClientImpl;
import com.etrade.etws.oauth.sdk.common.Token;
import com.etrade.etws.sdk.client.ClientRequest;
import com.etrade.etws.sdk.client.Environment;
import com.etrade.etws.sdk.common.ETWSException;
import com.etrade.*;

import java.awt.Desktop;
import java.net.URI;
import java.*;
import java.io.IOException;

public class OAuth
{
    public static void main(String[] args) throws IOException, ETWSException
    {
        //Variables
        IOAuthClient client = null;
        ClientRequest request = null;
        Token token = null;
        String oauth_consumer_key = null; // Your consumer key
        String oauth_consumer_secret = null; // Your consumer secret
        String oauth_request_token = null; // Request token 
        String oauth_request_token_secret = null; // Request token secret

        client = OAuthClientImpl.getInstance(); // Instantiate IOAUthClient
        request = new ClientRequest(); // Instantiate ClientRequest
        request.setEnv(Environment.SANDBOX); // Use sandbox environment
        request.setConsumerKey(oauth_consumer_key); //Set consumer key
        request.setConsumerSecret(oauth_consumer_secret);
        token = client.getRequestToken(request); // Get request-token object

        oauth_request_token  = token.getToken(); // Get token string
        oauth_request_token_secret = token.getSecret(); // Get token secret
    }

    public String Verification(String client, ClientRequest request)
    { 
         String authorizeURL = null;
         authorizeURL = client.getAuthorizeUrl(request); // E*TRADE authorization URL
         URI uri = new java.net.URI(authorizeURL);
         Desktop desktop = Desktop.getDesktop();
         desktop.browse(uri);

         return authorizeURL;
    }
}

堆栈跟踪

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<init>(OAuthClientImpl.java:22)
    at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<clinit>(OAuthClientImpl.java:24)
    at OAuth.main(OAuth.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more

推荐答案

您需要配置构建路径,以将Apache log4j记录器(org/apache/log4j/Logger)包含在外部JAR中.它的用途被隐藏在ETRADE代码中.

You need to configure your build path to include the Apache log4j logger (org/apache/log4j/Logger) in your external JARs. It's use is buried down in the ETRADE code.

您要在其中编辑代码?查找针对您的开发环境的说明应该很容易. APACHE是免费的,您可以在此处下载JAR: http://logging.apache.org/log4j/2.x/

What are you editing your code in? It should be easy to find instructions for your development environment. APACHE is free and you can download the JAR here: http://logging.apache.org/log4j/2.x/

请注意ETRADE(

Note the requirement from ETRADE (https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorialhttps://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorial): Java SDK To proceed with this tutorial, you must first have completed the installation of the E*TRADE Java SDK, including:

•已安装Java 1.6或更高版本

•Java 1.6 or later installed

•安装了第三方jars

•您的CLASSPATH中的E * TRADE Java SDK库

•E*TRADE Java SDK libraries in your CLASSPATH

您可以在此处 https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-SDKGuides-Java

例如,如果您使用的是Eclipse IDE,则可以按照以下说明进行操作

If you were using Eclipse IDE, for example, you can follow these instructions How to import a jar in Eclipse

这篇关于E * Trade OAuth API(Java)出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆