Search code examples
asp.nethttpsiis-7google-apigoogle-fit

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?


Solution

  • 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.