【发布时间】:2011-11-20 05:23:50
【问题描述】:
工作平台:ASP.NET 4.0 C#(与框架无关)
Google GData 是我的依赖项
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Documents;
我有两个页面 Auth 和 List。
Auth 像这样重定向到 Google Server
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 吗?如果有怎么办?
【问题讨论】:
-
您是否测试过您尝试通过客户端身份验证执行的查询?只是为了排除那部分的任何错误。
标签: c# asp.net oauth gdata-api google-docs