我正尝试使用Twitter API版本1.1和update_with_media.json方法将图像上传到Twitter。将图像上传到Twitter
https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
这是我到目前为止的代码,然而,尽管许多变化我不能让上传成功。
public TwitterResponse UpdateStatus(string message, String fileName, String contentType, byte[] image)
{
RestClient client = new RestClient
{
Authority = TwitterConstants.Authority,
VersionPath = TwitterConstants.Version
};
message = HttpUtility.HtmlEncode(message);
client.AddHeader("content-type", "multipart/form-data");
client.AddField("status", message);
client.AddField("media[]", Convert.ToBase64String(image) + ";filename=" + fileName + ";type=" + contentType);
RestRequest request = new RestRequest
{
Credentials = this.Credentials,
Path = "statuses/update_with_media.json",
Method = Hammock.Web.WebMethod.Post
};
return new TwitterResponse(client.Request(request));
}
我正在使用Hammock来执行这些请求。
只是为了排除可能的其他问题,我可以使用update.json方法成功向Twitter发布状态更新。
我也尝试过使用client.AddFile方法,并使用Fiddler它看起来像一切都已到位。不过,我不断收到后面的错误消息是
{"errors":[{"code":195,"message":"Missing or invalid url parameter"}]}
TweetSharp是我在项目结束时使用的,但它并没有没有困难。尽管现在是1.5年前。 –