Yammer API get/messages.json返回的结果不完整
问题描述:
将get/messages.json返回的数据与使用yammer中的导出检索的数据进行比较时。 get/messages.json返回6,300条记录。数据导出返回10,469条记录。与此post类似,我也在使用older_than参数。该帖子中有一条评论提出了一个限速问题。我可以向你保证,我不会超过费率限制,因为我在每10次请求后暂停15秒。Yammer API get/messages.json返回的结果不完整
为了让我不完整的6300行我...
使用导出API来获取所有的组
遍历组该列表的列表,并下载消息每个组使用
https://www.yammer.com/api/v1/messages/in_group/:group_id.json
然后我使用
https://www.yammer.com/api/v1/messages.json
和older_than参数来获取所有公司提要中的所有消息。
这个问题似乎是与步骤3
这里是与步骤3中的代码上面概述:
Sub GetAllCompanyMessages()
Try
Console.WriteLine("Getting All Company Messages")
If File.Exists(allCompanyPath) Then
'delete previous
If Directory.Exists(allCompanyPath) Then
For Each oldFile As String In Directory.GetFiles(allCompanyPath)
File.Delete(oldFile)
Next
Directory.Delete(allCompanyPath)
End If
'create dir
Directory.CreateDirectory(allCompanyPath)
Else
'create dir
Directory.CreateDirectory(allCompanyPath)
'Throw New Exception("Yammer Data Export Zip Download Failed")
End If
'get first group of messages
Console.WriteLine("Getting All Company Batch 1")
Dim client As New WebClient()
client.Headers.Add("Authorization", "Bearer " & accessToken)
client.DownloadFile(allCompanyMessagesURL, allCompanyPath & "1.json")
'getOlderThanID
Dim olderThanID As Int32 = getOlderThanID(allCompanyPath & "1.json")
'get remaining messages in batches of 20
Dim i As Int32 = 2
'Dim prevOlderThanID As Int32 = 0
Dim nextOlderThanID As Int32 = olderThanID
Do Until i = 0
Console.WriteLine("Getting All Company Batch " & i & " olderthanID " & nextOlderThanID)
client = Nothing
client = New WebClient()
client.Headers.Add("Authorization", "Bearer " & accessToken)
client.DownloadFile(allCompanyMessagesURL & "?older_than=" & nextOlderThanID, allCompanyPath & i & ".json")
'prevOlderThanID = nextOlderThanID
nextOlderThanID = getOlderThanID(allCompanyPath & i & ".json")
i = i + 1
If nextOlderThanID = 0 Then
'exit loop
i = 0
End If
' HANDLES 10 REQUESTS IN 10 SECONDS LIMIT
If i >= 10 Then
If i Mod 10 = 0 Then
' CAUSES APP TO WAIT 15 SECONDS AFTER EVERY 10th REQUEST
Console.WriteLine("Sleeping for 15 seconds")
System.Threading.Thread.Sleep(15000)
End If
End If
Loop
Console.WriteLine("Concatenating All Company Batches")
Dim masterJobject As New JObject
masterJobject = JObject.Parse("{""messages"":[]}")
For Each path As String In Directory.GetFiles(allCompanyPath, "*.json")
Console.WriteLine("Concatenating All Company Batch: " & path)
'open each json get messages object and append
Dim jObj As JObject = JObject.Parse(File.ReadAllText(path))
Dim jms As New JsonMergeSettings
'beh 5.24.17 jms.MergeArrayHandling = MergeArrayHandling.Union
jms.MergeArrayHandling = MergeArrayHandling.Concat
masterJobject.Merge(jObj, jms)
'File.Delete(path)
Next
Console.WriteLine("Building Yammer-All-Company-Messages.json")
File.WriteAllText(outputJSONpath & "Yammer-All-Company-Messages.json", "{ ""messages"":" & masterJobject("messages").ToString() & "}")
Catch ex As Exception
ErrorHandler("ERROR GetAllCompanyMessages: " & ex.Message)
End Try
End Sub
Function getOlderThanID(ByVal jsonPath As String) As Int32
Dim result As Int32 = 0
Try
Dim jObj As New JObject
jObj = JObject.Parse(File.ReadAllText(jsonPath))
If CBool(jObj("meta")("older_available")) = True Then
If Not IsNothing(jObj("messages").Last()("id")) Then
result = jObj("messages").Last()("id")
End If
End If
Catch ex As Exception
ErrorHandler("ERROR getOlderThanID: " & ex.Message)
End Try
Return result
End Function
我希望什么问题可能与任何见解get/messages.json API端点以及我如何修改我的代码来解决此问题。
答
对于将从REST API返回的消息项目数量存在技术限制。这些是为需要最新数据的客户端应用程序设计的。最好的选择是使用从REST API(api_url字段)对消息端点的单独调用来填充存档中的任何空白。确保一切都以持久的方式进行存储。
你怎么知道“空白”在哪里编程? – s15199d