0

我正在尝试使用google-api-ruby-client将 CurrentLocation 更新为 Google Latitude 。

我已经有一个访问令牌和刷新令牌,我从移动应用程序获得并通过 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
    }
}

提前致谢。

4

1 回答 1

0

调试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

于 2012-08-28T18:10:40.870 回答