需要帮助发布到Facebook中的页面。我用过这篇文章Post on Facebook User's wall 它的工作原理。但是,我试图发布的地方不是人墙,而是当用户登录脸书并点击右上角的齿轮符号时,它会显示“使用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工作。这是代码..希望它可以帮助别人...并再次感谢Mark。
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
答案 0 :(得分:1)
嗯...你发布到“/ me / feed”,它会发布到此人的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..