更新时间:2023-02-14 14:11:35
优秀教程:
http://www.daimto.com/google-drive-api-c/ [ ^ ]
试试这个Private Sub GetFileList(ParentFolder As String )
授权()' 照顾授权......你可以用JS来询问用户和获取Auth令牌
' MSO - 20130423 - 使用指定的foldername
' 创建搜索请求
Dim oListReq As Google.Apis.Drive.v2.FilesResource.ListRequest
Dim oFileList As FileList
' mimeType = ' application / vnd.google-apps.folder'
oListReq = oDriveService .Files.List()
' 搜索特定文件名
oListReq.Q = mimeType =' application / vnd.google-apps.folder ' and title =' + ParentFolder + ' 和trashed = false
oListReq.Fields =items / id' MSO - 20130621 - 仅限ID 下一个查询
oListReq.MaxResults = 10 ' 最多10个文件(也可能只有1个)
'获取结果
oFileList = oListReq .Fetch()' 预计只有1个结果 n> TODO:oFileList现在有文件夹中的文件列表,但可能有更多页面
如果oFileList.Items.Count = 1那么
Dim oFile As File = oFileList.Items(0)
FolderId = oFile.Id'获取FolderId
结束如果
oListReq = oDriveService.Files.List()
' 在
oListReq.Q =' + FolderId + ' 和trashed = false
' oListReq.Fields = items(id,alternateLink) ' MSO - 20130621 - 如果只需要某些字段,请优化查询
'获取结果
oFileList = oListReq.Fetch()
'
End Sub
I want to load my slider of image which image comes from google drive or one drive. i used below code for google drive but it returns all the files and i want to get from specific folder.
GoogleConnect.ClientId = "xxxxxx";
GoogleConnect.ClientSecret = "xxxxxx";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
GoogleConnect.API = EnumAPI.Drive;
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];
string json = GoogleConnect.Fetch("me", code);
GoogleDriveFiles files = new JavaScriptSerializer().Deserialize<GoogleDriveFiles>(json); // This will returns the files
}
else if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
excellent tutorial here:
http://www.daimto.com/google-drive-api-c/[^]
try thisPrivate Sub GetFileList(ParentFolder As String) Authorize() 'Take care of authorization... you could use JS to ask the user and get the Auth Token 'MSO - 20130423 - Search the Google Drive File with the specified foldername 'Create the search request Dim oListReq As Google.Apis.Drive.v2.FilesResource.ListRequest Dim oFileList As FileList 'mimeType = 'application/vnd.google-apps.folder' oListReq = oDriveService.Files.List() 'Search for a specific file name oListReq.Q = "mimeType = 'application/vnd.google-apps.folder' and title = '" + ParentFolder + "' and trashed=false" oListReq.Fields = "items/id" 'MSO - 20130621 - only ID needed for next query oListReq.MaxResults = 10 'Max 10 files (too may I Expect only 1) 'Get the results oFileList = oListReq.Fetch() 'Only 1 result is expected If oFileList.Items.Count = 1 Then Dim oFile As File = oFileList.Items(0) FolderId = oFile.Id 'Get FolderId End If oListReq = oDriveService.Files.List() 'Search for a specific file name in the folder oListReq.Q = "'" + FolderId + "' in parents and trashed=false " 'oListReq.Fields = "items(id,alternateLink)" 'MSO - 20130621 - Optimize your query if you need only certain fields 'Get the results oFileList = oListReq.Fetch() 'TODO: oFileList now have the list of the files in the folder, but there could me more "pages" End Sub