上传图像使用c#和Graph api进行提要

时间:2013-02-19 17:57:15

标签: c# facebook-graph-api

我需要将图像发布到我的墙上(用图像更新状态)。我如何使用C#和Graph Api(我不喜欢使用Facebook C#SDK)来做到这一点。图像在我的桌面上。我已经发布了一些文字和链接到Facebook但没有对下面给出的代码进行成像

string profile = string.Format(“https://graph.facebook.com/ {0} / Photo?access_token = {1}& picture = {2}& message = {3}”,_ userId,_fb.AccessToken,@ “C:\用户\ SANTANA \桌面\ sa.jpg”, “fasdf”);             WebRequest request = WebRequest.Create(profile);

        // Set the Method property of the request to POST.
        request.Method = "POST";
        // Create POST data and convert it to a byte array.
        string postData = "This is a test that posts this string to a Web server.";
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        // Set the ContentType property of the WebRequest.
        request.ContentType = "application/x-www-form-urlencoded";
        // Set the ContentLength property of the WebRequest.
        Stream dataStream = await request.GetRequestStreamAsync();
        // Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);
        // Close the Stream object.
        dataStream.Dispose();
        // Get the response.
        WebResponse response = await request.GetResponseAsync();

        // Display the status.

        // Get the stream containing content returned by the server.
        dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();
        // Display the content.
        tb.Text = responseFromServer;

0 个答案:

没有答案