1

Facebook のページに投稿するのに助けが必要です。私はこの記事を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

これら2つのクラスも必要です

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 に答える