0

I am struggling to call APIs hosted in Google Cloud https://apis-explorer.appspot.com/apis-explorer/?base=https%3A%2F%2Finnovative-glass.appspot.com%2F_ah%2Fapi#p/mirror/v1/

Up to my understanding, APIs are exposed as REST service. I need to make rest service call from .net application.

I have done OAuth Authentication. I am passing access_token as per the guidance given https://developers.google.com/accounts/docs/OAuth2WebServer

My Code:

UriBuilder uriBuilder = new UriBuilder("https://innovative-glass.appspot.com/_ah/api/mirror/v1/timeline");
string userId = Session["userId"] as string;
var state = Utils.GetStoredCredentials(userId);
NameValueCollection queryParameters = HttpUtility.ParseQueryString(uriBuilder.Query);
queryParameters.Set("access_token", state.AccessToken);
uriBuilder.Query = queryParameters.ToString();

var request = (HttpWebRequest)WebRequest.Create(uriBuilder.ToString());
request.Method = "GET";
var response = (HttpWebResponse)request.GetResponse();

I am getting UnAuthorized exception. Is my understanding is right? Am I doing right way?

1
  • I (like many here) don’t know the details of the .NET library. If you could have a peek at the HTTP going back and forth, there are a lot of people who might be able to spot a problem. Commented Oct 20, 2013 at 4:30

2 Answers 2

1

It seems that cloud endpoints don't use the Google API default of accepting access_token as query parameter. According to the Discovery document the equivalent query parameter is oauth_token so it should work with:

queryParameters.Set("oauth_token", state.AccessToken);

Alternatively (which in my opinion is the better solution) you can also set the Authorization header of the request instead of adding the token as query parameter:

request.Headers.Add("Authorization", "Bearer " + state.AccessToken);
Sign up to request clarification or add additional context in comments.

Comments

0

Where are you getting the AccessToken from, and are you sure it is still a valid token? Remember that access tokens expire about an hour after being generated, although can be revoked earlier.

Clicking on the sign-in button at innovative-glass.appspot.com gives me an origin mismatch error, so it looks like you may also have a configuration issue.

Have you been able to get it to work using just the API Explorer?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.