我正在尝试使用 Asana API 来更新和添加数据到 Asana。我如何在 C# 中做到这一点?
我得到的数据很好 - 下面的示例代码:
string apiKey = "xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxx";
var req = WebRequest.Create("https://app.asana.com/api/1.0/workspaces/xxxxxxxxxxxxxxx/projects");
var authInfo = apiKey + ":";
var encodedAuthInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
req.Headers.Add("Authorization", "Basic " + encodedAuthInfo);
var response = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
但我不知道如何发布数据。
他们文档中的所有示例都使用我没有经验的 Python。
我已联系 Asana,但尚未收到回复。这就是我到目前为止所拥有的。我在最后一行收到 400 错误
var url = "https://app.asana.com/api/1.0/workspaces/xxxxxxxxxxxxxxxxxxx/tasks";
string json =
"\"data\": { " +
"\"workspace\": nnnnnnnnnnnnnnnn," +
"\"name\": \"test\"," +
"\"notes\": \"testing API POST\"" +
"}";
byte[] bytes = Encoding.UTF8.GetBytes(json);
var req = WebRequest.Create(url) as HttpWebRequest;
req.Method = "POST";
req.ContentLength = bytes.Length;
req.ContentType = "application/json";
var requestStream = req.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
var response = req.GetResponse(); //error