Attualmente sto usando l'API di Facebook e C#.C# e Facebook API
Quello che sto cercando di fare è caricare un'immagine su un evento.
Ho provato due metodi, ma nessuno dei due sembra funzionare. Qualcuno potrebbe per favore dare un'occhiata.
Metodo 1
Dictionary<string, string> args = new Dictionary<string, string>();
string source = "@test.jpg";
string relpath = "/1234456789/photos";
args.Add("message", "sssssss");
args.Add("access_token", api.AccessToken);
args.Add("source", source);
api.Post(relpath, args);
Metodo 2
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("http://graph.facebook.com/1234456789/photos"));
request.ContentType = "multipart/form-data";
request.Method = "POST";
string path = HttpUtility.UrlEncode("test.jpg");
request.BeginGetRequestStream(ar =>
{
using (StreamWriter writer = new StreamWriter((ar.AsyncState as HttpWebRequest).EndGetRequestStream(ar)))
{
writer.Write("{0}={1}&", "message", HttpUtility.UrlEncode("Test"));
writer.Write("{0}[email protected]{1}&", "source", path);
writer.Write("{0}={1}", "access_token",
api.AccessToken);
}
}, request);
Metodo 3
WebClient client = new WebClient();
byte[] responseBinary = client.UploadFile("http://localhost:61689/Widgets/test2.aspx", "POST", @"C:\test.jpg");
string response = Encoding.UTF8.GetString(responseBinary);
Dictionary<string, string> args = new Dictionary<string, string>();
string relpath = "https://graph.facebook.com/me/picture";
args.Add("message", "sssssss");
args.Add("access_token", GetAccessToken(code));
args.Add("source", response);
api.Post(relpath, args);
Nel metodo 3 sto cercando di crea la risposta e scrivilo. Sto ricevendo 400 cattive richieste.
L'immagine 'test.jpg' si trova attualmente nella radice del mio sito Web, come nella pagina che la chiama.
Quando dici che non funziona, ricevi qualche errore? –
400 richiesta errata per il metodo 1, il metodo 2 viene eseguito solo ma non ottengo alcuna immagine su Facebook. Spero che questo ti aiuti. – Robert
La seguente domanda potrebbe essere d'aiuto: http://stackoverflow.com/questions/4210746/c-facebook-graph-how-to-upload-to-album-id. –