C# 如何在Unity中将媒体上传到twitter?
我正在Unity中创建TwitterClient,以便使用Unity资源进行推文 但此库没有媒体上载方法 所以我写了上传方法建模tweet方法 但它从TwitterAPI返回C# 如何在Unity中将媒体上传到twitter?,c#,unity3d,twitter,C#,Unity3d,Twitter,我正在Unity中创建TwitterClient,以便使用Unity资源进行推文 但此库没有媒体上载方法 所以我写了上传方法建模tweet方法 但它从TwitterAPI返回400错误请求:code 214错误请求 public static IEnumerator UploadPic(string picture, string consumerKey, string consumerSecret, AccessTokenResponse response, UploadPicCallback
400错误请求:code 214错误请求
public static IEnumerator UploadPic(string picture, string consumerKey, string consumerSecret, AccessTokenResponse response, UploadPicCallback callback)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
// parameters.Add("Content-Transfer-Encoding", "base64");
// Add data to the form to post.
WWWForm form = new WWWForm();
form.AddField("media_data", picture);
form.AddField("additional_owners", "");
//form.AddField("Content-Disposition", "form-data");
//form.AddField(picture, "");
// HTTP header
Dictionary<string, string> headers = new Dictionary<string, string>();
headers["Authorization"] = GetHeaderWithAccessToken("POST", UploadPicURL, consumerKey, consumerSecret, response, parameters);
headers["Content-Type"] = "multipart/form-data";
foreach (KeyValuePair<string, string> x in headers)
{
Debug.Log(x.Key + ":" + x.Value);
}
/*
string auth = GetHeaderWithAccessToken("POST", UploadPicURL, consumerKey, consumerSecret, response, parameters);
headers.Add("Authorization", auth);
headers.Add("Content-Type", "multipart/form-data");
*/
WWW web = new WWW(UploadPicURL, form.data, headers);
yield return web;
if (!string.IsNullOrEmpty(web.error))
{
Debug.Log(string.Format("UploadPic - failed. {0}\n{1}", web.error, web.text));
callback(false, web.error);
}
else
{
string error = Regex.Match(web.text, @"<error>([^&]+)</error>").Groups[1].Value;
if (!string.IsNullOrEmpty(error))
{
Debug.Log(string.Format("UploadPic - failed. {0}", error));
callback(false, web.error);
}
else
{
callback(true, web.text);
}
}
}
publicstaticienumerator UploadPic(字符串图片、字符串consumerKey、字符串consumerSecret、AccessTokenResponse响应、UploadPicCallback回调)
{
字典参数=新字典();
//添加(“内容传输编码”、“base64”);
//将数据添加到要发布的表单中。
WWWForm form=新WWWForm();
表单AddField(“媒体数据”,图片);
表格.AddField(“其他所有者”);
//AddField(“内容处置”、“表单数据”);
//表格.AddField(图片“”);
//HTTP头
字典头=新字典();
headers[“Authorization”]=GetHeaderWithAccessToken(“POST”、UploadPicURL、consumerKey、ConsumerCret、response、parameters);
标题[“内容类型”]=“多部分/表单数据”;
foreach(标头中的KeyValuePair x)
{
Debug.Log(x.Key+“:”+x.Value);
}
/*
字符串auth=GetHeaderWithAccessToken(“POST”,UploadPicURL,consumerKey,ConsumerCret,response,parameters);
添加(“授权”,auth);
添加(“内容类型”、“多部分/表单数据”);
*/
WWW-web=新的WWW(上传picurl、form.data、headers);
收益率;
如果(!string.IsNullOrEmpty(web.error))
{
Log(string.Format(“UploadPic-failed.{0}\n{1}”,web.error,web.text));
回调(false,web.error);
}
其他的
{
字符串错误=Regex.Match(web.text,@“([^&]+)”))。组[1]。值;
如果(!string.IsNullOrEmpty(错误))
{
Log(string.Format(“UploadPic-failed.{0}”,错误));
回调(false,web.error);
}
其他的
{
回调(true,web.text);
}
}
}
我的代码有什么问题?谢谢你的帮助