• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Post epoch time to web

Tom A

Member
Hi,

I have some VBA code to post a new event to the Meetup.com website using their API. I can post a draft event if I don't include the time variable when I post the data but it fails when I do.
The time is supposed to be the event start time based on milliseconds since standard epoch of 1/1/1970.

Would you be able to tell me if the below code is producing the time in epoch time? I can post the rest of the code if required.

EventDate = "01/12/2016"
time = DateDiff("S", "1/1/1970", EventDate)

Thank you,
Dave
 
1st of all, word 'Time' is a reserved word in VBA.
The result of 'Time' is current time.
Try to change is to something different.
 
Thanks Vletn, I've changed the name of the time variable but I'm still getting a 400 error response.

I've pasted my code below. I've removed my key and group name:

Code:
Sub CreateMeetupEvent()
Dim URL As String
URL = "https://api.meetup.com/2/event"

Dim Data As String
Data = meetupCreateEvent()
msgbox data
PostDataToURL URL, Data
End Sub

Sub PostDataToURL(URL As String, Data As String)
Dim xhr As Object
Dim strStatus As String

Set xhr = New MSXML2.XMLHTTP60
  Set xhr = CreateObject("MSXML2.XMLHTTP")
  xhr.Open "POST", URL, False
  xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  xhr.Send (Data)
  
  strStatus = xhr.Status
  If strStatus = "401" Then
  strStatus = "401 Unauthorized: The currently authenticated member can not create meetups in the specified group"
  ElseIf strStatus = "400" Then
  strStatus = "400 error response = event content appears to contain spam."
  ElseIf strStatus = "201" Then
strStatus = "HTTP 201 Event Created successfully. A Location header containing the Event Get method for this event. "
  End If
  
  MsgBox strStatus
End Sub

'http://www.meetup.com/meetup_api/docs/2/event/#create
 Function meetupCreateEvent() As String
Dim MyAPIKey As String
Dim group_urlname As String
Dim name As String
Dim EventDateAndTime As Long
Dim description As String
Dim publish_status As String
Dim Data As String
MyAPIKey = "MySecretKey"
'group_urlname = URL name of the Group hosting the event
group_urlname = "MyGroupName"

'name = Name of the event. May not be longer than 80 characters.
name = "This is a draft ignore"

'time is the event start time based on milliseconds since standard epoch of 1/1/1970.
EventDateAndTime = DateDiff("S", "1/1/1970", DateAdd("h", 5, "01/12/2016"))

'description = Longer description of the event, in HTML. May not be longer than 50000 characters.
description = "This is the description"
'publish_status = If you are an organizer of the group, you may set this to "draft" to save the event as a draft.
publish_status = "draft"

Data = "key=" & MyAPIKey & "&group_urlname=" & group_urlname & "&name=" & name & "&description=" & description & "&publish_status=" & publish_status & "&time=" & EventDateAndTime

meetupCreateEvent = Data
End Function
 
... the event start time based on milliseconds ...
and Your EventDateAndTime value is seconds (1480568400s) ?
Anyway, I cannot test more, sorry.
 
Back
Top