我有以下代码连接到Google时区api,并返回一个json消息,无论是否存在偏移量,我都会从中得出该消息。
问题:我在这里使用一个for循环,它为迭代1和它说的下一个迭代返回正确的消息
{“ errorMessage”:“提供的API密钥无效。”,“状态”:“ REQUEST_DENIED”}“
这是我的代码:
strArtifactoryUrl = "https://maps.googleapis.com/maps/api/timezone/json?"
apiKey = "AIzaSyCoJ1l1MkioDqYQNIDn7WsZjKv_inwktYM"
LatLongStr = "40.7142700,-74.0059700~United States###51.5085300,-0.1257400~United Kingdom"
Set session = New NotesSession
latVar = Split(LatLongStr,"###")
ForAll lv In latVar
If CStr(lv) <> "" Then
REM location based on latitude and longitude
strArtifactoryUrl = strArtifactoryUrl + "location=" +StrLeft(CStr(lv),"~")
REM UTC timestamp
Set usD = New NotesDateTime("12/01/2014 00:00:00")
Call usD.Adjustday(3)
strArtifactoryUrl = strArtifactoryUrl + "×tamp=" +CStr(getTimeStamp(usD.Lslocaltime)) &"&key=" & apiKey
c = StrRight(CStr(lv),"~")
Set httpObject = CreateObject("Msxml2.XMLHTTP")
Call httpObject.open("GET", strArtifactoryUrl, False)
Call httpObject.Send()
Print httpObject.responseText
End If
End forall
Function getTimeStamp(dt As Variant) As Long
Dim dtEpoch As New NotesDateTime("1/1/1970 00:00:00")
Dim dtTemp As New NotesDateTime(Now)
dtTemp.LSLocalTime = dt
getTimeStamp = dtTemp.TimeDifference(dtEpoch)
End Function
我用了一个采样日期。我的目标是每天运行一次,提前3天通知人们。感谢您的投入。您可以使用API密钥尝试一个免费帐户,因为它是免费帐户。
谢谢
问题是:您不需要strArtifactoryUrl
在第一次运行后重置变量,因此每次运行都会附加另一个位置和另一个时间戳,从而使url无效。
定义另一个名为strBaseUrl
的变量strArtifactoryUrl
,并从附加位置的那一行中的变量中形成变量。
这将是结果代码:
strBaseUrl = "https://maps.googleapis.com/maps/api/timezone/json?"
apiKey = "AIzaSyCoJ1l1MkioDqYQNIDn7WsZjKv_inwktYM"
LatLongStr = "40.7142700,-74.0059700~United States###51.5085300,-0.1257400~United Kingdom"
Set session = New NotesSession
latVar = Split(LatLongStr,"###")
ForAll lv In latVar
If CStr(lv) <> "" Then
REM location based on latitude and longitude
strArtifactoryUrl = strBaseUrl + "location=" +StrLeft(CStr(lv),"~")
REM UTC timestamp
Set usD = New NotesDateTime("12/01/2014 00:00:00")
Call usD.Adjustday(3)
strArtifactoryUrl = strArtifactoryUrl + "×tamp=" + _
CStr(getTimeStamp(usD.Lslocaltime)) &"&key=" & apiKey
c = StrRight(CStr(lv),"~")
Set httpObject = CreateObject("Msxml2.XMLHTTP")
Call httpObject.open("GET", strArtifactoryUrl, False)
Call httpObject.Send()
Print httpObject.responseText
End If
End forall
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句