現在Cybouzu live APIを利用するためにxAuthしようとしています。
に従い、
NuGetでOAuthライブラリである
rhargreaves/oauth-dotnetcore: An implementation of OAuth 1.0a for .NET Core based on Daniel Crenna's vaulted OAuth library
を導入し、
cs
1using OAuth; 2using System; 3using System.Net; 4using System.Text; 5 6namespace cybouzu_live_file_exporter_cui 7{ 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 13 try 14 { 15 OAuthRequest client = OAuthRequest.ForClientAuthentication( 16 consumerKey: "21891ba5535c668884211c9755f0feea8d4f39", 17 consumerSecret: "[secret key]", 18 username: "yume-wikijp@live.jp", 19 password: "[pass word]" 20 ); 21 client.RequestUrl = "https://api.cybozulive.com/oauth/token"; 22 client.Method = "POST"; 23 string auth = client.GetAuthorizationHeader(); 24 Console.WriteLine(auth); 25 var request = (HttpWebRequest)WebRequest.Create(client.RequestUrl); 26 request.Method = client.Method; 27 request.Headers.Add("Authorization", auth); 28 //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0"; 29 var response = (HttpWebResponse)request.GetResponse(); 30 var sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet)); 31 Console.WriteLine(sr.ReadToEnd()); 32 } 33 catch(WebException e) 34 { 35 Console.Error.WriteLine(e); 36 var res = (HttpWebResponse)e.Response; 37 var sr = new System.IO.StreamReader(res.GetResponseStream(), Encoding.GetEncoding(res.CharacterSet)); 38 Console.Error.WriteLine(sr.ReadToEnd()); 39 } 40 catch (Exception e) 41 { 42 Console.Error.Write(e); 43 } 44 } 45 } 46}
のようなコードをかいて実行したところ、
OAuth oauth_consumer_key="21891ba5535c668884211c9755f0feea8d4f39",oauth_nonce="[nonce]",oauth_signature="[signature]",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1520763181",oauth_version="1.0",x_auth_mode="client_auth",x_auth_password="[pass word]",x_auth_username="yume-wikijp%40live.jp" System.Net.WebException: リモート サーバーがエラーを返しました: (400) 要求が不適切です 場所 System.Net.HttpWebRequest.GetResponse() 場所 cybouzu_live_file_exporter_cui.Program.Main(String[] args) 場所 C:\Users\yumetodo\Documents\git\cybouzu_live_file_exporter\cybouzu_live_file_exporter_cui\Program.cs:行 32 oauth_problem=parameter_absent&oauth_parameters_absent=oauth_token
oauth_problem=parameter_absent&oauth_parameters_absent=oauth_token
と言われます。([]
でくくったものは公開できないので伏せていますが実際には適切な値が入っています)
今oauth_token
とoauth_token_secret
を要求しているのにoauth_token
がないとはどういうことなのかさっぱりです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。