I’m currently using ASP.NET 4.0 C# (Framework Agnostic) and relying on Google GData for my project. I’ve set up two pages: Auth and List. In the Auth page, I’m redirecting to the Google server for authentication as follows:
public ActionResult Auth()
{
var redirectUrl = Request.Url.ToString().ToLowerInvariant().Replace("auth", "list");
var scopeUrl = "https://docs.google.com/feeds/";
bool isSecure = false, useSession = true;
var authUrl = AuthSubUtil.getRequestUrl(redirectUrl, scopeUrl, isSecure, useSession);
return new RedirectResult(authUrl);
}
Upon successful authentication, it navigates to the List page:
public ActionResult List()
{
if (Request.QueryString["token"] != null)
{
string authToken = Request.QueryString["token"];
string appKey = "www.blahblah.net";
string appSecret = "my_key";
string sessionAuthToken = AuthSubUtil.exchangeForSessionToken(authToken, null).ToString();
var requestFactory = new GOAuthRequestFactory("writely", "qwd-asd-01");
requestFactory.Token = sessionAuthToken;
requestFactory.ConsumerKey = appKey;
requestFactory.ConsumerSecret = appSecret;
try
{
var documentService = new DocumentsService(requestFactory.ApplicationName) { RequestFactory = requestFactory };
var documentQuery = new DocumentsListQuery();
documentQuery.Title = "project";
var documentFeed = documentService.Query(documentQuery);
var documentTitles = documentFeed.Entries.ToList().ConvertAll(entry => entry.Title.Text);
return View(documentTitles);
}
catch (GDataRequestException)
{
throw;
}
}
}
This fails on the line that attempts to query for documents with the error:
Execution of request failed: https://docs.google.com/feeds/default/private/full?title=project
The catch block shows that the HttpStatusCode is HttpStatusCode.Unauthorized. What could be going wrong in this code? Is obtaining a TokenSecret necessary, and if so, how can I acquire it?