0

I am trying to update CurrentLocation to Google Latitude using google-api-ruby-client.

I already have an access token, and refresh token which I obtained from mobile app and sent to by server on Ruby on Rails. The following is the code which I am trying to execute.

    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

I am getting the following result:

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

I am not able to find out which Value that I pass is invalid. I tried to update the same set of values as below to https://www.googleapis.com/latitude/v1/currentLocation?key= and it worked.

Header:

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

Body:

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

Thanks in Advance.

buddy
  • 189
  • 2
  • 16

1 Answers1

0

Figured out the answer after debugging the gem code. The following is how the call has to be made.

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

Latitude API's look for :body instead of :parameters.

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
buddy
  • 189
  • 2
  • 16