添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi everyone, it is rare for me to post things and ask for advice, but this issue is just killing me.

I am trying to make a stupid simple call to request_token using C# (dotnet).

I have 2 attempts:
a) Using the example request here:
authentication/api-reference/request_token [I replaced with my callback url and key]

b) Using only the required header elements as described here (in step 1):
oauth-1-0a/obtaining-user-access-tokens

On the first one, I get 401, on the second one I get 400.
[I had to edit the urls so that I can create this post]

var url = “oauth/request_token”;
using (var client = new System.Net.Http.HttpClient { Timeout = TimeSpan.FromSeconds(60) })
var timestamp = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
var headerValue = “oauth_nonce = "mynoncevaluewillgohere", oauth_callback = "https%3A%2F%2FmyUrlDotCom%2Fconfirmtwitter", oauth_signature_method = "HMAC-SHA1", oauth_timestamp = "” + timestamp + “", oauth_consumer_key = "tzhUIRN0hrV6lCGW0r5taqYyV", oauth_signature = "Pc%2BMLdv028fxCErFyi8KXFM%2BddU%3D", oauth_version = "1.0"”;

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", headerValue);
            Console.WriteLine(client.DefaultRequestHeaders.Authorization.ToString());
            var result = client.PostAsync(url, new FormUrlEncodedContent(new List<KeyValuePair<string, string>>())).Result;
            if (result != null && result.IsSuccessStatusCode)
                Console.Write("success");
                Console.WriteLine("fail: " + result.StatusCode);
        using (var client = new System.Net.Http.HttpClient { Timeout = TimeSpan.FromSeconds(60) })
            var timestamp = ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString();
            var headerValue = "oauth_callback = \"https%3A%2F%2Fsportswatchmonitor.com%2Fhandicapper%2Fconfirmtwitter\",oauth_consumer_key = \"tzhUIRN0hrV6lCGW0r5taqYyV\"";
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", headerValue);
            Console.WriteLine(client.DefaultRequestHeaders.Authorization.ToString());
            var result = client.PostAsync(url, new FormUrlEncodedContent(new List<KeyValuePair<string, string>>())).Result;
            if (result.IsSuccessStatusCode)
                Console.Write("success");
                Console.WriteLine("fail: " + result.StatusCode);

May be I have been staring at this for so long I don’t see it, but here I am… lol… asking for some help.