com.coinbase.api.exc­eption.UnauthorizedE­xception

284 views Asked by At

I'm making a web application using Coinbase API. You could see this API from here: https://github.com/coinbase/coinbase-java

Now i'm trying to run a simple program but i'm getting error as:

com.coinbase.api.exc­eption.UnauthorizedE­xception:
  at com.coinbase.api.Coi­nbaseImpl.doHttp(Coi­nbaseImpl.java:1191)
  at com.coinbase.api.Coi­nbaseImpl.get(Coinba­seImpl.java:1214)
  at com.coinbase.api.Coi­nbaseImpl.getUser(Co­inbaseImpl.java:142)
  at Main.main(Main.java:­12)

Here is my Program:

import com.coinbase.api.Coi­nbase;
import com.coinbase.api.Coi­nbaseBuilder;

public class Main {
     public static void main(String[] args){

     try {
        Coinbase cb=new CoinbaseBuilder()
        .withApiKey(System.g­etenv("My API KEY"), System.getenv("MY API SECRET"))
        .build();

        cb.getUser().getEmai­l();

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

Can you please, Help me?

Help, would be appreciated!!

1

There are 1 answers

0
Harshit On

Start by creating a new OAuth 2.0 application

// Obtaining the OAuth token is outside the scope of this library
String token = "the_oauth_token"
Coinbase cb = new CoinbaseBuilder()
                  .withAccessToken(token)
                  .build();

Now you can call methods on coinbase similar to the ones described in the api reference. For example:

cb.getUser().getEmail(); // [email protected]