尝试使用他们的 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 并使用我的用户名/密码手动输入它,它工作正常。有什么建议么?谢谢洛基桑德斯