0

我想在身份验证文件夹查询行发送错误后从 google-drive 迭代文件夹。下面的代码显示身份验证过程,然后 itretating 文件夹但出现错误,请帮助我,等待回复。我不想在编码中使用用户凭据,我想使用客户端 ID 和客户端密码,以便任何人都可以登录到 Google 驱动器并迭代文件夹。


“请求执行失败:https ://docs.google.com/feeds/default/private/full/-/folder ”

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);


        }
4

1 回答 1

0

你这样做是完全错误的。您必须在https://developers.google.com/google-apps/documents-list/#authorizing_requests_with_oauth_20中添加更多代码, 您缺少的是添加service1.RequestFactory设置。此外,您不需要创建服务对象。

另请注意,您使用的是 Google Documents List API 3.0 版,该版本已于 2012 年 9 月 14 日正式弃用。

于 2012-10-23T07:26:27.277 回答