2

Note: You may be able to help me with this just by directing me to a place that explains well how to interface with web services. But help on this specific problem would be greatly appreciated!

I'm having a really hard time understanding how OAuth works. I'm trying to develop a desktop application which will upload a bunch of videos to accounts on Vimeo. I've tried tinkering a bit with the Scribe API and its examples. Scribe doesn't have a Vimeo example unfortunately, so I've been trying to alter the Facebook example to make it work for Vimeo. There's very little information on how this all works (that I've been able to 1: find, 2: understand). Here's what I have as far as code and errors:

public class VimeoTest
{
  private static final String NETWORK_NAME = "Vimeo";
  private static final Token EMPTY_TOKEN = null;

  public static void main(String[] args)
  {
    // Replace these with your own api key and secret
    String apiKey = "MYAPIKEY";
    String apiSecret = "MYAPISECRET";
    OAuthService service = new ServiceBuilder()
                                  .provider(VimeoApi.class)
                                  .apiKey(apiKey)
                                  .apiSecret(apiSecret)
                                  .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();
    OAuthRequest orequest = new OAuthRequest(Verb.GET, "http://vimeo.com/api/rest/v2");
    orequest.addQuerystringParameter("method", "vimeo.test.null");
    Response send = orequest.send();
    System.out.println(send.getBody());

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");
    Token requestToken = service.getRequestToken();

    //Breaks on the line above.
    //But I think it's because the orequest.send() returned a 100 error code

    String authorizationUrl = service.getAuthorizationUrl(requestToken);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Scribe here:");

    //I do NOT want to have to do this. Is there any other way I can have this authorize without going to a web browser to do this?

    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

Here's the output and Error:

=== Vimeo's OAuth Workflow ===

1.0
<?xml version="1.0" encoding="utf-8"?>
<rsp generated_in="0.0069" stat="fail">
  <err code="100" expl="The API key passed was not valid" msg="Invalid API Key" />
</rsp>
Fetching the Authorization URL...
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:47)
    at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:33)
    at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:118)
    at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:63)
    at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:43)
    at autouploadermodel.VimeoTest.main(VimeoTest.java:38)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64
    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:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 6 more
Java Result: 1

Anyway, I'll bet this is really simple, but I just don't understand how to interface with web services. Thanks for any help!

kentcdodds
  • 27,113
  • 32
  • 108
  • 187

1 Answers1

4

You need to include apache commons codec on your classpath

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • Well this is odd. This morning I tried including the apache commons codec (I actually feel dumb because I'm not sure how to do that, but I found a jar for version 1.6 and just included that as a library) and I `import org.apache.commons.codec.net.*;`. Then I ran it and it took me down to where I need to authorize the app in Vimeo. I copy and pasted the code Vimeo gave me and got a null pointer on this line: `Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);` `EMPTY_TOKEN` is declared as `null`, so that makes sense, but that's what the example had... I just don't really get it. – kentcdodds Mar 13 '12 at 13:37
  • Oh, and another weird thing is, if I remove the import of the codec, it works fine... That's the odd part I was talking about. So basically, my code looks exactly the same as it did yesterday when I was getting the error, but it gets further this time... My API Key was approved days ago, so I can't explain why this is, but... Yeah. Thanks for the help! – kentcdodds Mar 13 '12 at 13:38
  • Just ran it again and it's still saying my API key is invalid, but it gets the authorization url. This isn't making any sense to me. – kentcdodds Mar 13 '12 at 14:02
  • 1
    Your code not reaching the apache codec import exception is probably because the null pointer exception is happening before. **You do need commons codec in your classpath**. Period. If you experience further problems aside from that please create a new question and I'll be glad to help you :) – Pablo Fernandez Mar 13 '12 at 15:50
  • I'm so sorry Pablo. I must sound really dumb, but I can't figure out (or find a place to explain) how to add it to my classpath. I've added things to the classpath in environment variables before but I didn't understand what I was doing (and apparently I still don't). Could you please help me with that :-/ P.S. thanks for scribe! Reading up on how to do OAuth made it seem reeeeally complicated. Once I figure out how to use scribe I think it'll be a huge help :) – kentcdodds Mar 13 '12 at 16:11
  • Just for future comers, Pablo was totally right. But because I couldn't figure out how to add it to my classpath properly, I just included the jar file (haha, maybe that IS adding it to my classpath). Thanks Pablo! – kentcdodds Mar 16 '12 at 17:44