Twitter에서 인증 방식을 OAuth으로 바 꾸었습니다. 결국 앱을 업데이트 할 수 밖에 없었습니다. 나는 트위터가 작동하도록했다. (그래서 나는 나의 애플리케이션에 저장된 OAuth 정보를 가지고있다.) 이제 TwitPic API를 다시 작동시켜야합니다. 이 내가 찾은 OAuth를 처리 더 라이브러리는 없습니다, 그래서 내가 여기 내용에 따라 손으로 그것을 할 데 : 나는 천천히 그러나 확실하게이 무엇입니까TwitPic API cURL 예제를 C#, multipart data로 이식 하시겠습니까?
http://dev.twitpic.com/docs/2/upload/
나는 생각한다. 나는 어떤 종류의 물건이라도이 종류의 전문가가 아니다. 그러나 나는 그들의 다른 API 콜을 가지고있다. http://dev.twitpic.com/docs/2/users_show 그것은 이미지와 함께 멀티 파트 데이터가 아니지만 매력처럼 작동하고있다.
나는 더 많은 연구를 해보았으며, OAuth를 사용하여 멋진 Twitterizer 프레임 워크를 실현했다. 즉, 각 요청에 서명하고 OAuth 토큰을 약간만 전달하면된다. 그래서 TwitPic에 업로드하기위한 위 메소드 호출이 같은 방식으로 서명되어야한다는 것을 알아 챘습니다. 그것은 어려운 부분입니다 : 서명하고 웹 요청을 사용하여 전달하는 것입니다.
나도 혼란 스럽다. 그들은 OAuth 에코 부분이 보이는 헤더에 전달되는 서명을 말하는데, 이것은 C#의 System.Net.WebHeaderCollection webhc = new System.Net.WebHeaderCollection();
을 사용하여 헤더를 만드는 것과 동일하다.
나는 OAuth 토큰 (JSON에 직렬화)으로 요청한 요청을 받고 서명을 작성한 다음 실제 API를 호출하고 세 개의 매개 변수 (JSON Serialized)를 전달한다. 키, 메시지, 파일.
파일이 메모리 상주 파일이므로이 데이터를 전달하는 방법을 모르겠다.
string fileContentType = "image/jpeg";//GetImageContentType(filename);
string fileHeader = String.Format("Content-Disposition: file; name=\"{0}\"; filename=\"{1}\"", "media", filename);
string fileData = Encoding.GetEncoding(encoding).GetString(binaryImageData);
contents.AppendLine(fileHeader);
contents.AppendLine(String.Format("Content-Type: {0}", fileContentType));
contents.AppendLine();
contents.AppendLine(fileData);
말썽이 나는이 모든 사용하여 JSON을하려고하고 있다는 것이다 : 나는 이전 TwitPic 라이브러리에서 코드를해야합니까. FileContentType 등을 작성하여 StringBuilder 내용 객체에 추가하는 작업은 필자가 필요로하는 것보다 훨씬 많은 수동 작업처럼 보입니다.
내가 파일, 메시지 및 OAuth 토큰을 전달하는 Twitter의 새로운 승인을위한 TwitPic API가 있었으면 좋겠습니다. 아아 ... 올바른 방향으로 조종하는 것이 크게 감사 할 것입니다.
다음// <summary>
// Uploads the photo and sends a new Tweet
// </summary>
// <param name="binaryImageData">The binary image data.</param>
// <param name="tweetMessage">The tweet message.</param>
// <param name="filename">The filename.</param>
// <returns>Return true, if the operation was succeded.</returns>
public bool UploadPhoto(byte[] binaryImageData, string tweetMessage, string filename)
{
// Documentation: http://www.twitpic.com/api.do
string boundary = Guid.NewGuid().ToString();
string requestUrl = String.IsNullOrEmpty(tweetMessage) ? TWITPIC_UPLADO_API_URL : TWITPIC_UPLOAD_AND_POST_API_URL;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
string encoding = "iso-8859-1";
request.PreAuthenticate = true;
request.AllowWriteStreamBuffering = true;
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
request.Method = "POST";
string header = string.Format("--{0}", boundary);
string footer = string.Format("--{0}--", boundary);
StringBuilder contents = new StringBuilder();
contents.AppendLine(header);
string fileContentType = "image/jpeg";//GetImageContentType(filename);
string fileHeader = String.Format("Content-Disposition: file; name=\"{0}\"; filename=\"{1}\"", "media", filename);
string fileData = Encoding.GetEncoding(encoding).GetString(binaryImageData);
contents.AppendLine(fileHeader);
contents.AppendLine(String.Format("Content-Type: {0}", fileContentType));
contents.AppendLine();
contents.AppendLine(fileData);
contents.AppendLine(header);
contents.AppendLine(String.Format("Content-Disposition: form-data; name=\"{0}\"", "username"));
contents.AppendLine();
//contents.AppendLine(this.Username);
contents.AppendLine(header);
contents.AppendLine(String.Format("Content-Disposition: form-data; name=\"{0}\"", "password"));
contents.AppendLine();
//contents.AppendLine(this.Password.ToInsecureString());
if (!String.IsNullOrEmpty(tweetMessage))
{
contents.AppendLine(header);
contents.AppendLine(String.Format("Content-Disposition: form-data; name=\"{0}\"", "message"));
contents.AppendLine();
contents.AppendLine(tweetMessage);
}
contents.AppendLine(footer);
byte[] bytes = Encoding.GetEncoding(encoding).GetBytes(contents.ToString());
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
XDocument doc = XDocument.Parse(result);
XElement rsp = doc.Element("rsp");
string status = rsp.Attribute(XName.Get("status")) != null ? rsp.Attribute(XName.Get("status")).Value : rsp.Attribute(XName.Get("stat")).Value;
return status.ToUpperInvariant().Equals("OK");
}
}
}
}
이 응답은 Brandons Problem에 게시 된 것입니다 12/24/10 –