我想在验证文件夹查询行发送错误后从google-drive迭代文件夹。下面的代码显示验证过程然后找到文件夹但收到错误,请帮助我,等待回复。我不想在编码中使用用户凭证,我想使用客户端ID和客户端密码,以便任何人都可以登录到Google驱动器并迭代文件夹。
static void Main(string[] args)
{
String CLIENT_ID = "74138000159.com";
String CLIENT_SECRET = "8AE3oJuZomO";
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
var service = new DriveService(auth);
DocumentsService service1 = new DocumentsService("MyDocumentsListIntegration-v1");
// Instantiate a FolderQuery object to retrieve folders.
FolderQuery query = new FolderQuery();
// Make a request to the API and get all documents.
DocumentsFeed feed = service1.Query(query);
// Iterate through all of the documents returned
foreach (DocumentEntry entry in feed.Entries)
{
// Print the title of this document to the screen
Console.WriteLine(entry.Title.Text);
}
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
答案 0 :(得分:0)
你这样做完全错了。您必须在https://developers.google.com/google-apps/documents-list/#authorizing_requests_with_oauth_20中添加更多代码 您缺少的是添加 service1.RequestFactory 设置。您也不需要创建服务对象。
另请注意,您使用的是Google文档列表API 3.0版,该版本已于2012年9月14日正式弃用。