Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using HtmlAgilityPack;
- using System.Web;
- namespace NetflixAPI
- {
- static class OAuth1a
- {
- //gameplan:
- // target URL
- // Netflix params: Title, offset, limit
- // Oauth params: consumer_key, nonce, timestamp, signature_method
- //
- // and then the signature after, which is based on the above encoded
- //
- // HMAC outputs 20 chars, turn that to b64 then encode that
- //
- // NEed to encode certain chars AND make sure to encode it befre I pass
- // it to the MHA or whatever
- public static void Start()
- {
- string VERB = "GET";
- string URL = "http://api-public.netflix.com/catalog/titles";
- //Not going to change
- string consumer_key = "u7r68et24v6rd5r9u828qvte";
- string consumer_secret = "uWdp2AXnnu";
- string oauth_signature_method = "HMAC-SHA1";
- string oauth_version = "1.0";
- //dynamic values
- string oauth_timestamp = GenerateTimeStamp();
- string oauth_nonce = GenerateTimeStamp();
- // need to figure this out
- // string oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D";
- string oauth_signature = GenerateSignature(VERB, URL,
- consumer_key,
- consumer_secret,
- oauth_timestamp,
- oauth_nonce,
- oauth_signature_method,
- new KeyValuePair
- <string, string>(
- "term", "liar"),
- new KeyValuePair
- <string, string>(
- "start_index", "0"),
- new KeyValuePair
- <string, string>(
- "max_results", "25"));
- }
- public static string GenerateTimeStamp()
- {
- double time = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
- return Convert.ToInt32(time).ToString();
- }
- public static string GenerateNonce()
- {
- return Guid.NewGuid().ToString();
- }
- public static string GenerateSignature(string HttpMethod, string url,
- string consumer_key, string consumer_secret, string
- oauth_timestamp, string oauth_nonce, string
- oauth_signature_method= "HMACSHA1", params KeyValuePair<string,
- string>[] parameters)
- {
- //so this needs an encoded base string, which'll be
- //METHOD&URL&PARAMS
- //then I pass it to the HMAC-SHA1 which spits out a 20char, which'll
- //be encoded and used as sig param on the unencoded basestring
- //create BASESTRING where we already know the METHOD and URL, so we
- //need to grab all the params
- // string enc_params = GenerateEncodedParameterString(consumer_key
- // :"consumer_key" ,
- // oauth_signature_method :"oauth_signature_method" ,
- // oauth_version "oauth_version" , oauth_timestamp
- // :"oauth_timestamp" ,
- // oauth_nonce : "oauth_nonce" , parameters);
- KeyValuePair<string, string>[] qwe =
- {
- new KeyValuePair<string, string>("consumer_key",
- consumer_key),
- new KeyValuePair<string, string>("oauth_signature_method",
- oauth_signature_method),
- new KeyValuePair<string, string>("oauth_version",
- "1"),
- new KeyValuePair<string, string>("oauth_timestamp",
- oauth_timestamp)
- ,
- new KeyValuePair<string, string>("oauth_nonce", oauth_nonce)
- };
- parameters.ToList().AddRange(qwe.ToList());
- string enc_params = GenerateEncodedParameterString(parameters);
- //TODO: fix the hardcoded key
- string signString = consumer_key + "&";
- var encoded_signature = "asd";
- return encoded_signature;
- }
- public static string GenerateEncodedParameterString( params KeyValuePair<string,string>[] parameters)
- {
- var q = from entry in parameters
- let encodedkey = HttpUtility.UrlEncode(entry.Key)
- let encodedValue = HttpUtility.UrlEncode(entry.Value)
- let encodedEntry = encodedkey + "=" + encodedValue
- orderby encodedEntry
- select encodedEntry;
- var result = string.Join("&", q.ToArray());
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement