2009-11-11 107 views
1

我正嘗試使用Facebook Developer Toolkit(http://facebooktoolkit.codeplex.com/)從我的.NET應用程序發佈用戶消息。Facebook開發人員工具包 - 發佈消息

我有一個Facebook用戶的用戶ID。我的問題是,我如何發佈消息給這個用戶的Facebook流?目前,我寫的有以下代碼:

ConnectSession session = new ConnectSession(ApplicationKey, SecretKey); 
if (session.IsConnected()) 
{ 
    Api facebook = new Api(session); 
    Facebook.Schema.user user = facebook.Users.GetInfo(userID); 

    facebook.Stream.Publish("Hello"); 
} 

從最好的,我可以告訴,這個代碼只發布是在當前登錄用戶的消息。但我不認爲它用userID的流向用戶發佈消息。如何在具有特定用戶標識的流的Facebook用戶上發佈消息?

謝謝!

回答

0

你可以通過你想要發佈到其流的用戶的用戶ID:

facebook.Stream.Publish("Hello", null, null, null, userID); 

用戶必須已授予您的應用程序publish_stream當然前手擴展權限。

+0

對不起,我不能得到y我們的工作答案。我得到一個FacebookException,「當請求使用會話密鑰簽名時,必須指定一個會話密鑰」。任何提示? – 2010-02-03 08:33:28

1

嘗試第一次登錄...

try 
     { 
      servicio.ApplicationKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; 
      servicio.ConnectToFacebook(new List<Enums.ExtendedPermissions>() { Enums.ExtendedPermissions.read_stream, Enums.ExtendedPermissions.publish_stream }); 
      label2.Text = "Conectado:"; 
      label1.Text = servicio.Users.GetInfo().first_name + " " + servicio.Users.GetInfo().last_name; 
      pictureBox1.Image = servicio.Users.GetInfo().picture_small; 
      button2.Text = "Sesión Iniciada"; 
      button2.Enabled = false; 
      checkBox1.Enabled = true; 
      numericUpDown1.Enabled = true; 
      groupBox3.Enabled = true; 
      groupBox4.Enabled = true; 
     }catch (FacebookException fe) 
     { 

      listBox1.Items.Add(fe.Message); 
     } 

,那麼你可以發佈....這樣的..

try 
     { 
      var cancion = "lalalalala"; 
      String cosa = servicio.Stream.Publish(cancion, null, new List<action_link>() 
      { 
       new action_link() 
       { 
       text="Visita SQLeros", 
       href="http://sqleros.com.ar/wps" 

       } 
      }, null, 0); 
      servicio.Stream.AddLike(cosa); //to add like (Y) 
      listBox1.Items.Add(cosa); 

     } 
     catch (FacebookException fe) 
     { 

      listBox1.Items.Add(fe.Message); 
     } 

或這個.. N_N

try 
     { 
      String namePub = servicio.Users.GetInfo().first_name + "ha actualizado su estado"; 
      String cosa = servicio.Stream.Publish(richTextBox1.Text, 
      new attachment() 
      { 
       name = namePub, 
       href = "http://www.facebook.com/apps/application.php?id=136818146334647", 
       caption = "Tú tambien puedes usar Escuchando ahora, es facil y rapido", 
       properties = null, 
       media = new List<attachment_media>() 
       { 
        new attachment_media_image() 
        { 
         src="http://www.rammsdio.com.ar/images/img14781001.gif", 
         href = "http://www.facebook.com/apps/application.php?id=136818146334647" 
        } 
       } 
      }, 
      new List<action_link>() 
      { 
       new action_link() 
       { 
        text="Visita SQLeros", 
        href="http://www.sqleros.com.ar/wps" 
       } 
      },null,0); 
      listBox1.Items.Add("Has actualizado tu estado..."); 
      richTextBox1.Clear(); 
      if (checkBox2.Checked) 
       servicio.Stream.AddLike(cosa); 
     } 
     catch (FacebookException fb) 
     { 

      listBox1.Items.Add(fb.Message); 
     } 

我素不相識希望這對你有用..__