1

需要帮助发布到 facebook 中的页面。我在 Facebook 用户的墙上使用了这篇文章 Post 并且它有效。但是,我要发布的地方不是人物墙,而是当用户登录 Facebook 并单击右上角的齿轮符号时,它会显示“将 Facebook 用作:ThingX”,然后他们选择了 ThingX。这会将他们带到 ThingX 页面,这就是我想要发布的地方。在代码中,如果我以个人身份登录,它会发布到他们的墙上,而不是 ThingX。我如何发布到 ThingX 墙。

我将publish_stream,manage_pages作为代码传递..我不知道我是否需要在那里做一些不同的事情..

这是我现在使用的代码.. vb.net

Dim app_id As String = "xxxxxxxxxxxx"
    Dim app_secret As String = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    Dim scope As String = "publish_stream,manage_pages"

    If Request("code") Is Nothing Then
        Response.Redirect(String.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, Request.Url.AbsoluteUri, scope))
    Else
        Dim tokens As New Dictionary(Of String, String)()

        Dim url As String = String.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}", app_id, Request.Url.AbsoluteUri, scope, Request("code").ToString(), app_secret)

        Dim request__1 As HttpWebRequest = TryCast(WebRequest.Create(url), HttpWebRequest)

        Using response__2 As HttpWebResponse = TryCast(request__1.GetResponse(), HttpWebResponse)
            Dim reader As New StreamReader(response__2.GetResponseStream())

            Dim vals As String = reader.ReadToEnd()

            For Each token As String In vals.Split("&"c)
                'meh.aspx?token1=steve&token2=jake&...
                tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1))
            Next
        End Using

        Dim access_token As String = tokens("access_token")

        Dim client = New FacebookClient(access_token)

        client.Post("/me/feed", New With { _
         Key .message = "This is a test message -- " & Now.ToShortTimeString _
        })
    End If

想知道是否有人可以伸出援助之手。谢谢香农

~~~~~~~~~~~~~~~~~~~~~~~~~ 得到它的工作.. 下面的代码好吧.. 我终于得到这个工作,我可以发布到用户页面。在信用到期的地方给予信用.. http://www.markhagan.me/Samples/Grant-Access-And-Post-As-Facebook-User-ASPNet让我参与其中.. 然后是作者链接很友好,可以帮助我完成剩下的工作。我使用 Newtonsoft 来帮助我完成一些 JSon 工作。这是代码..希望它可以帮助其他人..再次感谢马克。

offline_access 允许您创建一个不会过期的令牌。

Dim app_id As String = "your app id"
    Dim app_secret As String = "your app secret"
    Dim scope As String = "publish_stream,manage_pages,offline_access"




    If Request("code") Is Nothing Then
        Response.Redirect(String.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, Request.Url.AbsoluteUri, scope))
    Else
        Dim tokens As New Dictionary(Of String, String)()
        Dim url As String = String.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}", app_id, Request.Url.AbsoluteUri, scope, Request("code").ToString(), app_secret)
        Dim request__1 As HttpWebRequest = TryCast(WebRequest.Create(url), HttpWebRequest)

            Using response__2 As HttpWebResponse = TryCast(request__1.GetResponse(), HttpWebResponse)
            Dim reader As New StreamReader(response__2.GetResponseStream())

            Dim vals As String = reader.ReadToEnd()

            For Each token As String In vals.Split("&"c)
                        tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1))
            Next
        End Using

    Try
        Dim access_token As String = tokens("access_token")

        Dim client = New FacebookClient(access_token)

        ' <-- put your USER access token here
        Dim p As JsonObject = CType(client.[Get]("/me/accounts"), JsonObject)

        Dim acc As jsondata = Newtonsoft.Json.JsonConvert.DeserializeObject(Of jsondata)(p.ToString)
        Dim accData As New List(Of AccountData)
        accData = acc.data


        Dim mList = From w In accData _
                  Where w.ID = CStr("your id value that came back through JSON) _
                  Select w

        Dim selected As New AccountData

        For Each selected In mList.ToList
        Next

        Dim postparameters = New Dictionary(Of String, Object)()
        postparameters("message") = Me.txtText.Text

        Dim client1 = New FacebookClient(selected.access_token)
        Dim result = DirectCast(client1.Post("/me/feed", postparameters), IDictionary(Of String, Object))

        Dim postid = DirectCast(result("id"), String)
        Return String.Empty
    Catch ex As Exception
        Return ex.Message.ToString
    End Try
    End If

你还需要这两个类

Private Class AccountData
    Public Property Name As String
    Public Property Category As String
    Public Property ID As String
    Public Property access_token As String
End Class
Private Class jsondata
    Public Property data As New List(Of AccountData)
End Class
4

1 回答 1

1

嗯...您正在发布到“/me/feed”,这将发布到该人的提要。要发布到其他用户或页面的墙,您需要发布到页面 ID。

https://developers.facebook.com/docs/reference/api/publishing/

引用:

You can publish to quite a few different kinds of objects via the Graph API:

Method  Description Arguments
/PROFILE_ID/feed    Publish a new post on the given profile's timeline. Note: requires publish permissions for the targeted profile.    message, picture, link, name, caption, description, source, place, tags
/OBJECT_ID/comments Comment on the given object (if it has a /comments connection)
and so on..
于 2013-05-17T19:20:26.897 回答