开发者

asp.net c# google api Documents - 401 Unauthorized

I have this code

DocumentsService vService = new DocumentsService("test");
vService.setUserCredentials("开发者_高级运维vUserName", "vPassword");
RequestSettings vSettings = new RequestSettings("test");
DocumentsRequest vDocReq = new DocumentsRequest(vSettings);
Feed<Document> vFeed = vDocReq.GetEverything();
foreach (Document d in vFeed.Entries) {
  lbxDocumente.Items.Add(d.Title + " " + d.Author);
}

Why do I get this exception?

System.Net.WebException: The remote server returned an error: (401) Unauthorized


This line is trying to authenticate with the actual strings "vUserName" and "vPassword":

vService.setUserCredentials("vUserName", "vPassword");

Did you mean it to be this instead, in order to use variables which you've initialized elsewhere?

vService.setUserCredentials(vUserName, vPassword);

(What's with the v prefix, by the way? I generally don't like prefixes like this at all, but I've never even seen v as a prefix before...)

EDIT: You're also not associating the request with the service anywhere. I've tried this code, and it works fine:

DocumentsService service = new DocumentsService("test");
service.setUserCredentials(user, password);
RequestSettings settings = new RequestSettings("test");
DocumentsRequest docReq = new DocumentsRequest(settings);
docReq.Service = service;
Feed<Document> feed = docReq.GetEverything();
foreach (Document d in feed.Entries) {
  Console.WriteLine(d.Title);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜