2011-03-27 96 views
0

我寫了一個Facebook的應用程序,但我無法上傳圖像到我創建的相冊, 代碼在下面,感謝您的幫助。如何將照片張貼到相冊在facebook圖表api Asp.NET

 Facebook.FacebookAPI api = new Facebook.FacebookAPI(GetAccessToken()); 
     Dictionary<string, string> album = new Dictionary<string, string>(); 
     album.Add("name", "Test Album"); 
     album.Add("message", "Message here!"); 
     JSONObject result = api.Post("me/albums", album); 
     string AlbumId = result.Dictionary["id"].String; 

     Dictionary<string, string> photo = new Dictionary<string, string>(); 
     photo.Add("message", "test Message"); 
     photo.Add("source", "tgw.jpg"); 
     JSONObject photoResult = api.Post("/" + AlbumId + "/photos", photo); 

回答

1

這是否適合您?

string photoPath = @"..\..\..\Facebook.Tests\bin\Release\monkey.jpg"; 
      string albumId = ConfigurationManager.AppSettings["AlbumId"]; 
      byte[] photo = File.ReadAllBytes(photoPath); 

      FacebookApp app = new FacebookApp(); 
      dynamic parameters = new ExpandoObject(); 
      parameters.access_token = ConfigurationManager.AppSettings["AccessToken"]; 
      parameters.message = "This is a test photo of a monkey that has been uploaded " + 
           "by the Facebook C# SDK (http://facebooksdk.codeplex.com)" + 
           "using the Graph API"; 
      var mediaObject = new FacebookMediaObject 
      { 
       FileName = "monkey.jpg", 
       ContentType = "image/jpeg", 
      }; 
      mediaObject.SetValue(photo); 
      parameters.source = mediaObject; 

      dynamic result = app.Api(String.Format("/{0}/photos", albumId), parameters, HttpMethod.Post); 

here

+0

摘自我會看它感謝 – Xenon 2011-03-29 14:11:11

+0

我沒有app.Api方法我認爲我們的SDK的是不同的:(我的是https://github.com/facebook/ csharp-sdk – Xenon 2011-03-29 14:14:07

+0

我認爲你應該真的切換到這個微軟的SDK http://facebooksdk.codeplex.com/ 它只是偉大的 – 2011-03-29 14:37:36

相關問題