【问题标题】:Trying to update Google Latitude of CurrentLocation using google-api-ruby-client returns "400 Invalid Value"尝试使用 google-api-ruby-client 更新 CurrentLocation 的 Google Latitude 返回“400 Invalid Value”
【发布时间】:2012-08-28 06:58:27
【问题描述】:

我正在尝试使用 google-api-ruby-client 将 CurrentLocation 更新为谷歌纵横。

我已经有一个访问令牌和刷新令牌,我从移动应用程序获取并通过 Ruby on Rails 上的服务器发送到该令牌。以下是我正在尝试执行的代码。

    client = Google::APIClient.new(:key => gltoken)
    client.authorization.client_id = '<my client id>'
    client.authorization.client_secret = '<my client secret>'

    client.authorization.access_token = "<the access token i ve>"
    client.authorization.refresh_token = "<refresh token i ve>"
    client.authorization.scope ='https://www.googleapis.com/auth/latitude.all.best https://www.googleapis.com/auth/latitude.current.best'

    client.host = "www.googleapis.com"
    latitudeapi = client.discovered_api('latitude', 'v1')

    result = client.execute(
      :api_method => 'latitude.currentLocation.insert',
      :parameters => {
        'kind' => 'latitude#location',
        'latitude'=>37.420352,
        'longitude'=>-122.083389,
        'accuracy'=>130,
        'altitude'=>35
    }
    )

    logger.debug("Response #{result.body}")
    result.body

我得到以下结果:

 {"message":"{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"invalid\",\"message\":\"Invalid Value\"}],\"code\":400,\"message\":\"Invalid Value\"}}"}

我无法找出我传递的值无效。我尝试将与下面相同的一组值更新为https://www.googleapis.com/latitude/v1/currentLocation?key=,并且成功了。

标题:

Content-Type: application/json
Authorization: Bearer <My access token>
Host: googleapis.com

主体:

{
  "data": {
    "kind":"latitude#location",
    "latitude":37.420352,
    "longitude":-122.083389,
    "accuracy":130,
    "altitude":35
    }
}

提前致谢。

【问题讨论】:

    标签: ruby-on-rails google-latitude


    【解决方案1】:

    调试 gem 代码后想出答案。以下是如何进行调用。

    result = client.execute(
                :api_method => 'latitude.currentLocation.insert',
                :body => "{\"data\": {\"kind\":\"latitude#location\",\"latitude\":#{latitude},\"longitude\":#{longitude}}}",
                :headers => {'Content-Type'=> 'application/json'}
             )
    

    Latitude API 寻找 :body 而不是 :parameters

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 2013-08-03
      相关资源
      最近更新 更多