I have two FB page feeds and I am trying to join them together in one object (or list, or array) that I can read, sorted on "created_time" data. I have changed question code after comments.
Here's my JSON data:
{
"data": [
{
"message": "Zimovanje u punom tijeku :-)",
"created_time": "2017-01-04T10:06:57+0000",
"type": "photo",
"name": "Photos from Odred izvi\u0111a\u010da Javor's post",
"id": "217384491624554_1572127976150192"
},
{
"message": "Skup\u0161tina Odreda izvi\u0111a\u010da tijeku...",
"created_time": "2016-12-22T19:52:12+0000",
"type": "photo",
"name": "Timeline Photos",
"id": "217384491624554_1552374844792172"
},
...
And here is my code until now:
Public Class FBData
Public Property data As New List(Of FBFeed)
End Class
Public Class FBFeed
Public Property message As String
Public Property created_time As DateTime
Public Property id As String
Public Property type As String
Public Property name As String
End Class
Public Shared Function GetPosts( PageId As String, accessToken As String ) As FBData
Dim APIlink As String = "https://graph.facebook.com/" & pageID & "/posts?fields=full_picture,message,created_time,id,link,type,name,description&access_token=" & accessToken
Dim client As New WebClient()
client.Encoding = System.Text.Encoding.UTF8
Dim strJson As [String] = client.DownloadString(APIlink)
Dim result As FBData = Newtonsoft.Json.JsonConvert.DeserializeObject(Of FBData)( strJson )
Return result
End Function
In main code I am calling this function:
Dim array1 As FBData = GetPosts ( "OI.Plavipingvin", accessToken )
Dim array2 As FBData = GetPosts ( "217384491624554", accessToken )
'Merging two lists
array1.data.AddRange(array2.data.ToArray)
'Order final list
Dim OrderedPosts as List(Of FBFeed) = array1.data.OrderByDescending(Function(x) x.created_time)
For Each Msg As FBFeed In array1.data
Response.Write( Msg.created_time & "<br />" )
Response.Write( "<image width=""100px"" height=""100px"" src=""" & Msg.full_picture & """><br />" )
Next
The line Dim OrderedPosts as List produces error System.InvalidCastException: Unable to cast object of type 'System.Linq.OrderedEnumerable 2[_feed+FBFeed,System.DateTime]' to type 'System.Collections.Generic.List 1[_feed+FBFeed]'..