Netflix API Forums

Netflix API Feature Requests

RSS Feed

HMAC_SHA1 - what library to use

    • Ranker
    • Topic created 3 years ago

    I want am trying to get the first signature done - the request URL, customer key and customer secret. Could anyone please tell me what library or class i need to use for that. Thanks in advance

    Message edited by Ranker 2 years ago

    Tags

  1. Ranker3 years ago

    I am working in Java btw

  2. JR Conlin3 years ago

    If you're using this for Netflix, I'd recommend using John Haren's Netflix Client Library, which handles a large portion of this process for you.

    If you're just interested in using OAuth, there are other Java libraries that also encapsulate encoding.

    All of these are available under the "Resources" tab

  3. Ranker3 years ago

    Hi, Thanks for posting. I have downloaded almost all the available libraries from netflix api "Resource" tab for Java.

    I want make a signed request to Netflix with my request URL, my consumer key and consumer secret. All the implementations ask for consumer secret and token secret (which confuses me). Token secret is supposed to be sent by netflix once we make the initial signed request. My ultimate intention is to be able to access user queues.

    If anyone can tell me the exact library (file name, class name) that will help me getting the initial signed request, I'll be very thankful

    Thanks again.

  4. JR Conlin3 years ago

    Ah, for that, it might be useful to use Kent's OAuth Walkthrough (again, on the Resources Page). This will show you where the various bits are used, and how you acquire them.

  5. Ranker3 years ago

    Thanks again for your post.

    I have used the demo walk through. It is very helpful, but what I want is an encryption method that will sign my request URL with my consumer secret. I have had a hard time to figure out what method to use out of all the libraries.

    Any suggestion welcome.

  6. JR Conlin3 years ago

    Ah, for that, I'd recommend reading John's guide at the URL where you downloaded his library:

    http://blueleftistconstructor.com/projects/netflix-client/

  7. Ranker3 years ago

    Hey JR,
    Thanks so much for replying.

    I have got the first step working. I am able to generate a link where user can sign in and I am able to redirect the user to my specified callback url. Now, I want to get the access token so I can get the user ID for accessing the user queues. As you might remember, I am using Java and the oauth client library from resources tab

    Here is the code snipped where I'm getting problem:
    ----------------------------------------
    OAuthRequestToken reqToken = apiClient.getNewRequestToken();

    String callbackURL = "http://www.ranker.com";
    String redirectURL = apiClient.getNetflixAuthorizationURL(reqToken, callbackURL);

    System.out.println("New Request token: " + reqToken); // just for checking purpose
    System.out.println("Redirect URL: " + redirectURL); // same

    OAuthAccessToken accessToken = apiClient.exchangeRequestTokenForAccessToken(reqToken);
    System.out.println("Access token: " + accessToken);
    ----------------------------------------

    And the output :
    ------------------------
    New Request token: oauth_token=ae9u4fakn36w94etsv7vgjd3&oauth_token_secret=wvfQMY4SVCBk&application_name=Ranker

    Redirect URL: http%3A%2F%2Fapi-user.netflix.com%2Foauth%2Flogin%3Foauth_token%3Dae9u4fakn36w94etsv7vgjd3%26oauth_consumer_key%3D66gsp32trvxfdgn5j9zdhpby%26application_name%3DRanker%26accept_tos%3Dtrue%26output%3Dpox%26oauth_callback%3Dhttp%3A%2F%2Fwww.ranker.com

    Access token: oauth_token=null&user_id=null&oauth_token_secret=null
    ------------------------

    I dont understand why I'm getting null for all the above parameters.

    Can you please suggest where am I going wrong.
    Kindly reply. Thanks in advance.

  8. John Haren3 years ago

    My first guess would be that the request token you have is not being authorized. In your above sample I can see where you get the auth URL to give to the user, but unless the user goes to that location and grants access the request token you have won't work. You're likely getting a 400 response and the access token will have null values in that case.

    An easy way to tell: if the access token's values come back null, you can also call its getErrorCause() method, which will return the HTTP status line of the exchange call.
    Another way to find out: add the line
    log4j.logger.com.netflix.api.client.dal.HttpMethodBuilder=DEBUG
    to your log4j.properties file and run through the scenario, then look for output from the HttpMethodBuilder.exchangeRequestForAccessToken() method. If you see a 400 class response it's what I'm thinking, and if you see token text there's a bug in my code :(

  9. Ranker3 years ago

    Hi John,
    Thanks for your reply.
    I tried using the auth URL for user sign in. I am able to let the user sign in and authenticate the token. But every time after I am redirected to the callback URL, I get the same token that I passed as the authorized token. So, I thought I would use the same token for to exchange for access token. I completely agree with you that unless the user authorizes that token its not authorized, could please tell me what api calls do I make to get things done.

    Thanks

  10. Ranker3 years ago

    You are right, For accessToken.getErrorCause(), I am getting :
    Error cause :HTTP/1.1 401 Unauthorized

    Its just that I am a little confused with what calls to make. Is there a function in the library that can authorize the token by letting user to sign in so that I can pass the authorized token to exchangeRequestTokenForAccessToken function??

    Thanks

  11. John Haren3 years ago

    Well, remember that the entire intention of OAuth is to have the user grant access to a 3rd-party application without exposing his credentials to that app. So, as far as the series of calls is concerned, you (1) get a request token, (2) send the user off to netflix.com to auth the request token, and then (3) exchange the request token for the access token. It appears something's going wrong with your step (2). Above, you've obtained the URL to redirect your user to so they can auth, but it's truncated here in the posting, so I can't see what your callback URL is. In any event, make sure your callback URL is valid and able to continue the process (after the user auths, netflix will call your callback endpoint with the now-authorized request token; it's here that you'll continue with the call to exchange it for an access token).

  12. Tim Endres2 years ago

    Dear John,

    Over and over your documentation says "(3) exchange the request token for the access token." However, NOWHERE do you show the magic for how this is done. I have scoured the net for any working example of this single step and I cannot find a single one. I am beginning to believe that there is no one on this planet who has successfully completed this step.

    Sincerely,
    tim.

  13. Kirsten Jones2 years ago

    Tim,

    Please read the documentation for the Java library here: http://www.blueleftistconstructor.com/projects/netflix-java-client/usage.html

    It includes a walkthrough of turning a request token into an access token. Note that you need to have the user approve the application, and use the token in the callback from that to request the access token. This is all covered in the walkthrough in the documentation.

    Kirsten

  14. Tim Endres2 years ago

    I posted a more complete response in thread #63964. The bottom line is that the Usage documentation does not explain how to convert the oauth_token returned by the NF callback into a proper OAuthRequestToken Java object needed for the call to exchangeRequestTokenForAccessToken(). Furthermore, there is nothing in the documentation about setting the application name, which seems to be required for the call to getNetflixAuthorizationURL(). Still looking for a complete example of working code.

[ Page 1 of 1 ]