2013-05-17 36 views
1

需要幫助張貼到Facebook的頁面。我用這篇文章Post on Facebook User's wall 它工作。然而,我試圖發佈的地方不是人牆,而是當用戶登錄到臉書並點擊右上角的齒輪符號時,它會顯示「Use Facebook as:ThingX」,然後他們選擇ThingX。這將他們帶到ThingX頁面,那就是我想要發佈到的地方。在代碼中,如果我以人身份登錄,它將張貼到他們的牆上,而不是ThingX。我如何張貼到ThingX牆。Facebook張貼到頁面不是用戶牆

我傳遞在publish_stream,manage_pages作爲代碼..我不知道,如果我需要做不同的事情有..

這裏是我現在使用.. VB代碼。網

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 

回答

1

嗯......你發佈到「/我/飼料」,which'll張貼到人的飼料。要發佈到其他用戶或頁面的牆上,您需要發佈到頁面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.. 
+0

對不起我的無知..我用指Facebook的條款我是路要走。我需要爲ThingX頁面創建一個應用程序嗎?我嘗試從ThingX頁面去開發人員,但它希望我去那裏登錄的用戶..有道理我猜...但我不知道如果我需要有一個應用程序創建在ThingX頁面。如果沒有,你是說我可以使用我已經創建併發布到ThingX頁面的應用程序..但我如何找出ThingX的PROFILE_ID。再次,謝謝你的幫助 – jvcoach23

+0

只需進入facebook頁面並放置一個「圖表」。在它的前面,例如「http://graph.facebook.com/CrystalicBandOfficial」而不是「https://www.facebook.com/CrystalicBandOfficial」。你將在返回的json對象中擁有你的id。 – Michael