Hello Ka-Ping!
When I follow ur link http://latitudesample.appspot.com/
I am getting this message:
Your location is: {"data":{"kind":"latitude#location"}}
You need to set the Content-Type header field to "application/json",
if you are submitting the location in JSON format, or
"application/atom+xml" if you are using the Atom format.
Cheers,
Ana
Hi Ted,Sorry, I can't tell what the issue is. (Latitude is not my main project; I just dabbled in it to make the sample app.) Maybe someone on the google-latitude-api group will be able to help.
—Ping
Google Crisis Response
On Sun, Feb 6, 2011 at 09:40, egilchri <egil...@gmail.com> wrote:Hello Ping,
I've been beating my head against the wall quite a while my next
problem. BTW, I used your sample code to write a mashup called
Moveable Weather, and it worked great. Now I'd like to write a method,
call it "update_current_location", which is like get_current_location
here:
http://code.google.com/p/latitudesample/source/browse/app/latitude.py
but is used to update my current location with data like this:
{'data': {
'timestampMs': my_time,
'kind':'latitude#location',
'latitude':0.0,
'longitude':0.0
}}
It seems like it should be simple, but so far it has eluded me. My
latest attempt is below, but returns a server error. Any hints or
pointer you can give would be appreciated.
Thanks,
Ted Gilchrist
def update_current_location(self, data):
request = oauth.OAuthRequest.from_consumer_and_token(
self.client.get_consumer(),
token=self.client.get_token(),
http_method='POST',
http_url=Latitude.REST_URL % ('currentLocation',),
parameters={'granularity': 'best', 'body': data}
)
request.sign_request(
self.client.signature_method,
self.client.get_consumer(),
self.client.get_token())
returned = self.client.access_resource(request)
content = returned.content
status = returned.status_code
logging.info ("Returned: %s content: %s status: %s" %
(returned, content, status))
return returned
On Aug 9 2010, 2:12 pm, Ka-Ping Yee <k...@google.com> wrote:
> Hello,
>
> To help you get started with the Google Latitude API, we've posted a sample
> application at:
>
> http://code.google.com/p/latitudesample
>
> This application is also running at:
>
> http://latitudesample.appspot.com/
>
> This is a minimal application that carries out authorization and then shows
> your current location.
>
> The app uses open source Python modules for OAuth written by Joe LaPenna and
> Leah Culver, and factors out the OAuth stuff to help you get past the OAuth
> dance and get started building your app. Your application code only needs
> to follow the example in
> shouldn't need to change oauth.py, oauth_appengine.py, or
> oauth_webapp.py).
>
> Hope this helps! Please see the project's README
> more details, and feel free to ask questions on this group.
>
> — Ping
> Google Crisis Response
What's the error that you are getting back? The example JSON you are
trying to submit is sane, so that is not the problem.
A common pitfall is that the signature is not correct, because you
forgot to put all your parameters into it before signing. Are you
using a specific OAuth library? (Is so, which?) Or are you doing the
signing by hand?
Unrelated to the problem you are seeing, but just a tip: when
submitting a currentLocation, the server will set the timestamp to the
time at which you performed the POST, so you can omit the timestampMs
field from your location JSON. (The timestamp, however, is required
when submitting historical locations.)
Cheers,
Ana
This is linked from "Libraries and samples" section of the Latitude API docs:
http://code.google.com/apis/latitude/libraries.html
Cheers,
Ana
When I modify the sample latitude.py script, by putting this:
print p.currentLocation().get().execute()
print p.currentLocation().insert(body=body).execute()
print p.currentLocation().get().execute()
I get
{u'kind': u'latitude#location'}
{u'kind': u'latitude#location', u'altitude': 35, u'longitude': -100.083389, u'latitude': 37.420352000000001, u'timestampMs': u'1297305858102', u'accuracy': 130}
{u'kind': u'latitude#location'}
So even though the second print statement really does modify my Google Latitude location, (which I can verify by just going to the Google Latitude interactive map), the 1st and 3rd aren't returning any object from which I can glean my actual current position.
Cheers,
Ana
So, In Latitude, I moved my avatar to San Francisco, a well-known metropolis, and it worked. I got back lat and lng. So, this works, when I am in SF.
print p.currentLocation().get().execute()
So then I tried adding granularity="best" in various ways. This seems like how it should be:
** print p.currentLocation().get(granularity='best').execute()
The reason this seems right is that when I use a bogus keyword, other than "granularity", it tells me it doesn't know that parameter.
However, the result I get back, when I do ** above is
apiclient.errors.HttpError: <HttpError 401 "Invalid Credentials">
Any thoughts?
When you got your OAuth token, you probably didn't ask for access to
best-available granularity, so your token is only giving you access to
city-level locations. As a result, when you request best-available
locations, you get back a 401 authorization error. You need to go back
through the OAuth flow to get yourself access to best-available
granularity.