如果我在google drive web界面中创建一个新文件夹,则无法通过c#中的api调用来检索元数据。
但是,如果我通过api上传文件或创建文件夹,则会按预期返回元数据。
问题与此相反(几乎),用户无法在通过api上传的Web界面中看到文件... I can't see the files and folders created via code in my Google Drive
在google驱动器网络界面中我可以看到所有文件,但我只在下面的代码中获取通过api创建的文件的详细信息。
(编辑)我应该补充一点,我已经尝试过使用每一个' DriveService.Scope'我可以使用。
(edit2)我观察到,如果我更改ApplicationName,则也不会检索以前上传的文件,但是新上传的文件都是。
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name, size, mimeType)";
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
return files;
CTOR
public GoogleDrive(string appname)
{
ApplicationName = appname;
error = new Error();
try
{
credential = GetCredential();
}
catch(Exception ex)
{
error = ex as Error;
}
try
{
// Create Drive API service.
service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.ApplicationName,
});
}
catch (Exception ex)
{
error = ex as Error;
}
}
GetCredential方法
private UserCredential GetCredential()
{
UserCredential credential;
try
{
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/gd-cred-" + ApplicationName + ".json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
return credential;
}
catch (Exception ex)
{
error = ex as Error;
return null;
}
}