다양한 기능 중에서 사용자가 로그인하여 드라이브의 파일에 액세스 할 수 있도록 Google 드라이브에 C# 응용 프로그램을 포함하고 싶습니다. 나는이 웹과 다른 소스 코드를 많이 연구하고, 나는 다음과 같은 하나 성공했다 :Google 드라이브가 포함 된 C#
UserCredential credential;
using (var stream =
new FileStream("client_id.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Drive API service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
//listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
// List files.
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
Console.WriteLine("Files:");
if (files != null && files.Count > 0)
{
foreach (var file in files)
{
Console.WriteLine("{0} ({1})", file.Name, file.Id);
}
}
else
{
Console.WriteLine("No files found.");
}
Console.Read();
나는 개발자를위한 Google 드라이브의 웹 사이트에 내 자격 증명을 얻어야했다입니다. 이 코드는 제대로 작동하지만 애플리케이션의 모든 사용자가 직접 Google 드라이브 자격증 명을 생성해야하므로이 작업을 자동화하는 방법을 알 수 없습니다.
내 목표는 Google 이메일 및 비밀번호 입력을위한 두 개의 상자를 표시하는 사용자 인터페이스를 제공 한 다음 인증을 위해 작업을 수행하고 성공하면 사용자는 해당 파일에 액세스 할 수 있습니다.
이 URL [URL] (http://stackoverflow.com/help)을 확인하십시오. 콘텐츠 품질을 높이는 것이 유용 할 것입니다. –