3

尝试使用他们的 api 访问谷歌电子表格。按照他们的例子,代码不起作用,原因也不明显。我要做的就是连接,但我不断收到同样的错误。这是他们在 2010 年 4 月 15 日设置的代码。任何人都可以就我做错了什么提供任何建议吗?代码:

using System;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Spreadsheets;




namespace google_spreadsheet
{
    class Program
    {
        static void Main(string[] args)
        {
            SpreadsheetsService myService = new SpreadsheetsService("MySpreadsheet" );
            myService.setUserCredentials("account@gmail.com", "xxxxxxx");
            string token1 = myService.QueryClientLoginToken();
            Console.WriteLine("token is {0}", token1);
            Console.ReadLine();
            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = myService.Query(query);
           Console.WriteLine("list");
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                Console.WriteLine("Value: {0}", entry.Title.Text);

当我运行它时,它在 myService.Query 语句中不断出错,并出现以下错误:

Google.GData.Client.GDataRequestException was unhandled
  Message=Execution of request failed: http://spreadsheets.google.com/feeds/spreadsheets/private/full
  Source=Google.GData.Client
  ResponseString=<HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

  StackTrace:
       at Google.GData.Client.GDataRequest.Execute()
       at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
       at Google.GData.Client.GDataGAuthRequest.Execute()
       at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
       at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince)
       at Google.GData.Client.Service.Query(FeedQuery feedQuery)
       at Google.GData.Spreadsheets.SpreadsheetsService.Query(SpreadsheetQuery feedQuery)
       at google_spreadsheet.Program.Main(String[] args) in C:\Development Items\VS Projects\VS2008\google_spreadsheet\google_spreadsheet\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Net.WebException
       Message=The remote server returned an error: (404) Not Found.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at Google.GData.Client.GDataRequest.Execute()
       InnerException: 

然而,我可以获取网址 http://spreadsheets.google.com/feeds/spreadsheets/private/full 并使用我的用户名/密码手动输入它,它工作正常。有什么建议么?谢谢洛基桑德斯

4

2 回答 2

0

我对 Mono 也有类似的问题。就我而言,这是 SSL 使用的证书问题。

于 2010-06-16T13:08:31.623 回答
0

我相信这是因为你没有在文档查询对象中指定 Uri 试试这个

DocumentsService service = new DocumentsService("appName");
service.Credentials = new GDataCredentials("email@gmail.com", "password");

DocumentQuery query = new DocumentQuery("http://docs.google.com/feeds/default/private/full/-/contents");
query.Categories.Add(DocumentsListQuery.SPREADSHEETS);

var spreadsheets = service.Query(query).Entries.Cast<DocumentEntry>();
于 2010-10-12T09:58:04.413 回答