vb.net - Get picture URL in google drive -
i want url of picture exist in google drive , show in forms , try method in nothing here code
..... createservice() dim tab() string = fichier.split(".") dim list = service.files.list() list.q = "trashed=false" list.fields = "nextpagetoken, items(id, title)" dim count = list.execute() each fich in count.items if (fich.title) = fichier dim path string = fich.webcontentlink dim mywebclient new system.net.webclient dim imageinbytes() byte = mywebclient.downloaddata(path) dim imagestream new io.memorystream(imageinbytes) affich_image.image.image = new system.drawing.bitmap(imagestream) end if fich.webcontentlink value nothing fichier string , name of file exist in gridview
here working vb.net code drive v2 & oauth 2.0 so post:
imports system.threading imports system.threading.tasks imports google imports google.apis.auth.oauth2 imports google.apis.drive.v2 imports google.apis.drive.v2.data imports google.apis.services imports google.apis.auth imports google.apis.download 'dev console: 'https://console.developers.google.com/ 'nuget command: 'install-package google.apis.drive.v2 private service driveservice = new driveservice private sub createservice() if not begreen dim clientid = "your client id" dim clientsecret = "your client secret" dim myusercredential usercredential = googlewebauthorizationbroker.authorizeasync(new clientsecrets() {.clientid = clientid, .clientsecret = clientsecret}, {driveservice.scope.drive}, "user", cancellationtoken.none).result service = new driveservice(new baseclientservice.initializer() {.httpclientinitializer = myusercredential, .applicationname = "google drive vb dot net"}) end if end sub private sub uploadfile(filepath string) me.cursor = cursors.waitcursor if service.applicationname <> "google drive vb dot net" createservice() dim thefile new file() thefile.title = "my document" thefile.description = "a test document" thefile.mimetype = "text/plain" dim bytearray byte() = system.io.file.readallbytes(filepath) dim stream new system.io.memorystream(bytearray) dim uploadrequest filesresource.insertmediaupload = service.files.insert(thefile, stream, thefile.mimetype) me.cursor = cursors.default msgbox("upload finished") end sub private sub downloadfile(url string, downloaddir string) me.cursor = cursors.waitcursor if service.applicationname <> "google drive vb dot net" createservice() dim downloader = new mediadownloader(service) downloader.chunksize = 256 * 1024 '256 kb ' figure out right file type base on uploadfilename extension dim filename = downloaddir & "newdoc.txt" using filestream = new system.io.filestream(filename, system.io.filemode.create, system.io.fileaccess.write) dim progress = downloader.downloadasync(url, filestream) threading.thread.sleep(1000) while progress.status = taskstatus.running loop if progress.status = taskstatus.rantocompletion msgbox("downloaded!") else msgbox("not downloaded :(") end if end using me.cursor = cursors.default end sub to url, here code:
dim request = service.files.list() request.q = "mimetype != 'application/vnd.google-apps.folder' , trashed = false" request.maxresults = 2 dim results = request.execute each result in results.items msgbox(result.downloadurl & vbcrlf & result.title & vbcrlf & result.originalfilename) next for further insight of needed, check documentation.
Comments
Post a Comment