来自 GetResultData 的消息 ID

发布于 2025-01-08 01:40:28 字数 1777 浏览 0 评论 0原文

我似乎无法获取或存储我创建的帖子消息的 ID。我正在使用此代码发布消息:

Try

        Dim fb = New FacebookClient(_accessToken)

        AddHandler fb.PostCompleted, Function(o, e)
                                         If (e.Cancelled) Then

                                         ElseIf e.Error IsNot Nothing Then
                                             MessageBox.Show(e.Error.Message)
                                         Else
                                             Dim result As Object = e.GetResultData()
                                             _lastMessageId = result.Id
                                         End If
                                         Return MessageBox.Show("Message Posted successfully")
                                     End Function

        Dim parameters As Object = New ExpandoObject()
        parameters.message = TextBox1.Text
        fb.PostTaskAsync("me/feed", parameters)

        MsgBox("This is the last message id " & _lastMessageId)

    Catch ex As FacebookApiException
        MessageBox.Show(ex.Message)
    End Try 

我只想存储发布的 ID,以便稍后删除它。

这是我想出的工作代码,感谢普拉比尔

  Dim fb = New FacebookClient(_accessToken)

    Dim parameters As Object = New ExpandoObject()
    parameters.message = "Testing"

    Dim task = fb.PostTaskAsync("me/feed", parameters)

    task.ContinueWith(Function(t)

                          If t.Exception Is Nothing Then

                              Dim result As Object = t.Result
                              _lastMessageId = result.id

                          Else

                              MsgBox("error occurred")

                          End If

                          Return t.Result

                      End Function)

I cannot seem to get or store the id of the post message I create. I am using this code to post a message:

Try

        Dim fb = New FacebookClient(_accessToken)

        AddHandler fb.PostCompleted, Function(o, e)
                                         If (e.Cancelled) Then

                                         ElseIf e.Error IsNot Nothing Then
                                             MessageBox.Show(e.Error.Message)
                                         Else
                                             Dim result As Object = e.GetResultData()
                                             _lastMessageId = result.Id
                                         End If
                                         Return MessageBox.Show("Message Posted successfully")
                                     End Function

        Dim parameters As Object = New ExpandoObject()
        parameters.message = TextBox1.Text
        fb.PostTaskAsync("me/feed", parameters)

        MsgBox("This is the last message id " & _lastMessageId)

    Catch ex As FacebookApiException
        MessageBox.Show(ex.Message)
    End Try 

I just want to store the posted id so I can delete it later.

Here is the working code that i came up with thanks to prabir

  Dim fb = New FacebookClient(_accessToken)

    Dim parameters As Object = New ExpandoObject()
    parameters.message = "Testing"

    Dim task = fb.PostTaskAsync("me/feed", parameters)

    task.ContinueWith(Function(t)

                          If t.Exception Is Nothing Then

                              Dim result As Object = t.Result
                              _lastMessageId = result.id

                          Else

                              MsgBox("error occurred")

                          End If

                          Return t.Result

                      End Function)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何时共饮酒 2025-01-15 01:40:28

这是 C# 代码,可能会帮助您开始使用它。

由于您使用的是 XTaskAsync 方法,请使用 ContinueWith 而不是 PostCompleted。

fb.PostTaskAsync("me/feed", parameters)
  .ContinueWith(t= > {
    if(!t.IsFaulted) {
      dynamic result = t.Result;
    }
  });

XTaskAsync 方法返回 Task

here is c# code which might help you get started with it.

Since you are using XTaskAsync methods use ContinueWith instead of PostCompleted.

fb.PostTaskAsync("me/feed", parameters)
  .ContinueWith(t= > {
    if(!t.IsFaulted) {
      dynamic result = t.Result;
    }
  });

XTaskAsync methods returns Task<object>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文