Twitter API バージョン 1.1 と update_with_media.json メソッドを使用して、画像を 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"}]}