Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

asp.net - Google Fit Api 403 Error from remote client

I have a web app hosted on IIS 7 that is doing Http calls using the Google Fit API, I'm able to successfully send a POST and retrieve an access token, after which I do a GET for the following uri:

"https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.weight:com.google.android.apps.fitness:user_input/datasets/00-1427209862000000000"

Here's how I build a request and look at the response:

        request = (HttpWebRequest)WebRequest.Create(uri);
        request.Method = "GET";
        request.ContentLength = 0;
        request.Accept = "application/json";
        request.Headers.Add("Authorization", "Bearer " + dict["access_token"]);
        response = (HttpWebResponse)request.GetResponse();
        respStream = response.GetResponseStream();
        sResponse = new StreamReader(respStream).ReadToEnd();
        respStream.Close();
        Response.Write(sResponse);

When I run this app on a browser on the host server, I successfully get a json object (it isn't the json I expect, but that's another issue). However, when I try to access the site on a remote client, I get a 403 error pointing to when I try to retrieve the response. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It probably depends how you got the access_token value.

How long after retrieving the access token are you making this request? It's only valid for an hour, so you may need to fetch a new one using the refresh token.

There's some more resources on access/refresh tokens this question:

Google OAuth2 Refresh_token expires when Access_token does


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...