【问题标题】:Facebook Developer Toolkit - Publishing a MessageFacebook 开发者工具包 - 发布消息
【发布时间】:2024-04-24 23:05:01
【问题描述】:

我正在尝试使用 Facebook 开发者工具包 (http://facebooktoolkit.codeplex.com/) 从我的 .NET 应用程序中发布用户消息。

我有一个 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 的流向用户发布消息。如何使用特定用户 ID 的流向 Facebook 用户发布消息?

谢谢!

【问题讨论】:

    标签: c# .net facebook


    【解决方案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);
            }
    

    或者这个..ñ_ñ

    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);
            }
    

    我希望这对你有用..ñ_ñ

    【讨论】:

      【解决方案2】:

      您可以传递要发布其流的用户的用户 ID:

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

      当然,用户必须事先授予您的应用程序 publish_stream 扩展权限。

      【讨论】:

      • 抱歉,我无法得到您的答复。我收到一个 FacebookException,“使用会话密钥对请求进行签名时必须指定会话密钥”。有什么提示吗?
      最近更新 更多