【问题标题】:Google Timezone API: Request LoopGoogle 时区 API:请求循环
【发布时间】:2014-11-09 02:48:15
【问题描述】:

我有以下代码连接到 google timezone api 并返回一个 json 消息,如果有偏移量,我将从该消息中得出。

问题:我在这里使用了一个 for 循环,它为迭代 1 和下一次迭代返回正确的消息

{ "errorMessage" : "提供的 API 密钥无效。", "status" : "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 + "&timestamp=" +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 密钥来试用您的免费帐户。

谢谢

【问题讨论】:

    标签: lotusscript google-maps-timezone


    【解决方案1】:

    问题是:您没有在第一次运行后重置变量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 + "&timestamp=" + _
                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
    

    【讨论】:

    • 同意。错过了那个愚蠢的错误。感谢您指出。
    猜你喜欢
    • 2019-10-16
    • 2023-03-16
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多