Google Fit Api 403 Error from remote client

限于喜欢 提交于 2019-12-13 04:55:06

问题


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?


回答1:


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




回答2:


Update: This turned out to be a permissions issue. I was trying to access a data source that I didn't have scopes for, the fact that it didn't return a 403 when accessing on the host threw me off the trail. Still strange that it didn't return a 403 (it just returned an empty json object) when requested on the host server though...if you see this and have an idea why, feel free to comment. I'm curious.



来源:https://stackoverflow.com/questions/29281957/google-fit-api-403-error-from-remote-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!