工作平臺:ASP.NET 4.0 C#(框架不可知論)訪問谷歌文檔與的GData
谷歌的GData是我的依賴
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Documents;
我有兩個頁面驗證和列表。
驗證重定向到谷歌服務器這樣
public ActionResult Auth()
{
var target = Request.Url.ToString().ToLowerInvariant().Replace("auth", "list");
var scope = "https://docs.google.com/feeds/";
bool secure = false, session = true;
var authSubUrl = AuthSubUtil.getRequestUrl(target, scope, secure, session);
return new RedirectResult(authSubUrl);
}
現在到達列表頁面,如果認證成功。
public ActionResult List()
{
if (Request.QueryString["token"] != null)
{
String singleUseToken = Request.QueryString["token"];
string consumerKey = "www.blahblah.net";
string consumerSecret = "my_key";
string sessionToken = AuthSubUtil.exchangeForSessionToken(singleUseToken, null).ToString();
var authFactory = new GOAuthRequestFactory("writely", "qwd-asd-01");
authFactory.Token = sessionToken;
authFactory.ConsumerKey = consumerKey;
authFactory.ConsumerSecret = consumerSecret;
//authFactory.TokenSecret = "";
try
{
var service = new DocumentsService(authFactory.ApplicationName) { RequestFactory = authFactory };
var query = new DocumentsListQuery();
query.Title = "project";
var feed = service.Query(query);
var result = feed.Entries.ToList().ConvertAll(a => a.Title.Text);
return View(result);
}
catch (GDataRequestException gdre)
{
throw;
}
}
}
這種失敗在與錯誤的行var feed = service.Query(query);
的要求執行失敗:https://docs.google.com/feeds/default/private/full?title=project
收到catch塊上的HttpStatusCode
是HttpStatusCode.Unauthorized
什麼是錯的用這個代碼?我需要獲取TokenSecret嗎?如果是這樣如何?
您是否測試了您嘗試使用客戶端身份驗證執行的查詢?只是爲了排除該部分的任何錯誤。 –