我正在努力调用托管在 Google Cloud 中的 API https://apis-explorer.appspot.com/apis-explorer/?base=https%3A%2F%2Finnovative-glass.appspot.com%2F_ah%2Fapi#p/mirror /v1/
据我了解,API 是作为 REST 服务公开的。我需要从 .net 应用程序进行休息服务调用。
我已经完成了 OAuth 身份验证。我按照给出的指导传递 access_token https://developers.google.com/accounts/docs/OAuth2WebServer
我的代码:
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();
我收到未经授权的异常。我的理解对吗?我做得对吗?