public static Dictionary <string, string> GetAccessToken() { Dictionary <string, string> dictAccessTokens = new Dictionary <string, string>(); const string consumerKey = ""; const string consumerSecret = ""; //Authorization request Uri baseUrl = AppKeys.GetBaseUri(); RestClient oauthClient = new RestClient(baseUrl) { Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret) }; RestRequest request = new RestRequest("oauth/request_token", Method.POST); IRestResponse response = oauthClient.Execute(request); NameValueCollection qs = HttpUtility.ParseQueryString(response.Content); string oauthToken = qs["oauth_token"]; string oauthTokenSecret = qs["oauth_token_secret"]; string loginUrl = qs["login_url"]; Process.Start(loginUrl); string verifier = Console.ReadLine(); //request = new RestRequest("oauth/authorize"); //request.AddParameter("oauth_token", oauthToken); //string url = oauthClient.BuildUri(request).ToString(); request = new RestRequest("oauth/access_token", Method.POST); oauthClient.Authenticator = OAuth1Authenticator .ForAccessToken(consumerKey, consumerSecret, oauthToken, oauthTokenSecret, verifier); response = oauthClient.Execute(request); NameValueCollection qs2 = HttpUtility.ParseQueryString(response.Content); oauthToken = qs2["oauth_token"]; oauthTokenSecret = qs2["oauth_token_secret"]; dictAccessTokens.Add("accessToken", oauthToken); dictAccessTokens.Add("accessToeknSecret", oauthTokenSecret); Console.WriteLine("Access: {0} - Access Secret {1}", oauthToken, oauthTokenSecret); Console.ReadLine(); return(dictAccessTokens); }
public static void ShippingSummaries() { string path = @"C:\Internal\Shipping Summary.xls"; string sheet = "Shipping Summary"; var data = ReadFrom(path, sheet); var summaries = data.Select(x => new { CompanyID = x["Company_ID"].ToString(), OrderNumber = x["Order_No"].ToString(), Tracking = x["Tracking"].ToString() }).ToList(); var gclient = InternalClientService.GetInternalClientByID(summaries.First().CompanyID); if (gclient != null) { var client = new RestClient(); client.BaseUrl = AppKeys.GetBaseUri(); client.Authenticator = OAuth1Authenticator.ForProtectedResource(AppKeys.GetApiKey(), AppKeys.GetSharedSecretKey(), gclient.AccessToken, gclient.AccessSecretKey); ShopService SS = new ShopService(); ReceiptService RS = new ReceiptService(); var receipts = SS.GetShopReceipts(client, gclient.EtsyShopIDs.First()); foreach (var summary in summaries) { Console.WriteLine("Updating Receipt : {0}", summary.OrderNumber); var receipt = receipts.FirstOrDefault(x => x.order_id == summary.OrderNumber); if (receipt != null) { if (!bool.Parse(receipt.was_shipped)) { Console.WriteLine("Receipt Status : {0}", RS.UpdateReceipt(client, receipt.receipt_id)); Thread.Sleep(1000); } //submit tracking Console.WriteLine("Transcation Status : {0}", RS.SubmitTracking(client, receipt.receipt_id, gclient.EtsyShopIDs.FirstOrDefault(), summary.Tracking, "USPS")); Thread.Sleep(1000); } } } }