なんてこった、私は自分のヘッダーを書くことからC#の例を変換することまですべてを試しましたが、写真をアップロードするときの400 Bad Requestエラーを乗り越えることができません.
可能なすべての権限が追加されており、トークンは正しいです。
ステータスの更新をフィードに投稿できますが、画像をアップロードできません。ここに私が試した2つの異なるアプローチがあり、どちらも400 Bad Requestを返します...
1
Dim myReq As HttpWebRequest
Dim myRes As HttpWebResponse
Dim encoding As New System.Text.ASCIIEncoding()
Dim postData As String
Dim data() As Byte
Dim sr As StreamReader
Dim imagedata As String
imagedata = File.OpenText("C:\ebay00042-1.jpg").ReadToEnd()
postData += "access_token=MY_TOKEN_HERE_29ZB51pPizthxX5lhmst3MZC7hYXQhW8ZB8e7sVVLzEaN8ZCZAzAgrzk1pisw3ZCtK5lwMMTZBUhe07xTsQvfeHosA1GFUAZDZD&message=this is a test123&source=" & imagedata 'File.ReadAllBytes(photoPath)
data = encoding.GetBytes(postData)
myReq = WebRequest.Create("https://graph.facebook.com/380406275386560/photos")
DirectCast(myReq, System.Net.HttpWebRequest).UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
myReq.Method = "POST"
myReq.ContentType = "application/x-www-form-urlencoded"
myReq.ContentLength = data.Length
Dim myStream As Stream = myReq.GetRequestStream
myStream.Write(data, 0, data.Length)
myStream.Close()
myRes = myReq.GetResponse
sr = New StreamReader(myRes.GetResponseStream)
Dim strHTML As String = sr.ReadToEnd
2、独自のヘッダーを作成しようとしています..
Dim myReq As HttpWebRequest
Dim myRes As HttpWebResponse
Dim encoding As New System.Text.ASCIIEncoding()
Dim data() As Byte
Dim sr As StreamReader
Dim boundary As String = "----------" + DateTime.Now.Ticks.ToString("x")
Dim sb As StringBuilder = New StringBuilder("")
sb.Append("----------").Append(boundary).Append("\r\n")
sb.Append("Content-Disposition: form-data; name=""access_token""").Append("\r\n")
sb.Append("\r\n")
sb.Append("MY_TOKEN_HERE_MZC7hYXQhW8ZB8e7sVVLzEaN8ZCZAzAgrzk1pisw3ZCtK5lwMMTZBUhe07xTsQvfeHosA1GFUAZDZD").Append("\r\n")
sb.Append("----------").Append(boundary).Append("\r\n")
sb.Append("Content-Disposition: form-data; name=""message""").Append("\r\n")
sb.Append("\r\n")
sb.Append("Testttt").Append("\r\n")
sb.Append("----------").Append(boundary)
sb.Append("Content-Disposition: file; name=""source"" filename=""ebay00042-1.jpg""").Append("\r\n")
sb.Append("Content-Type: image/jpeg).Append(\r\n")
'sb.Append("Content-Transfer-Encoding: binary").Append("\r\n")
sb.Append("\r\n")
sb.Append(File.OpenText("C:\ebay00042-1.jpg").ReadToEnd()).Append("\r\n")
sb.Append("----------").Append(boundary).Append("----------").Append("\r\n")
'txtCaption.Text = sb.ToString
data = encoding.GetBytes(sb.ToString)
myReq = WebRequest.Create("https://graph.facebook.com/380406275386560/photos")
DirectCast(myReq, System.Net.HttpWebRequest).UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
myReq.Method = "POST"
myReq.ContentType = "multipart/form-data; boundary=" + boundary
'myReq.ContentType = "application/x-www-form-urlencoded"
myReq.ContentLength = data.Length
Dim myStream As Stream = myReq.GetRequestStream
myStream.Write(data, 0, data.Length)
myStream.Close()
myRes = myReq.GetResponse
sr = New StreamReader(myRes.GetResponseStream)
Dim strHTML As String = sr.ReadToEnd
どんな助けでも大歓迎です!