使用javascript从Google云端硬盘获取文件元数据 [英] Use javascript to get file metadata from Google drive

查看:86
本文介绍了使用javascript从Google云端硬盘获取文件元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个代码,可以将文件插入到Google云端硬盘中,然后显示文件ID和其他信息中的可共享链接。

我需要使用文件iD获取文件元数据,我有代码这是Javascript,但我不知道如何使用它

Javascript代码

I have code in C# that inserts a file into Google Drive and them displays file ID and shareable link amongst other information.
I need to get file metadata using the file iD, I have the code that is Javascript, but I do not know how to use it
Javascript Code

<pre lang="HTML"><pre><script type="text/javascript">

        function printFile(fileId) {
            var theID = '0B2XoJnBPsMpeaTdrX2pibl9GOE0';
            var request = gapi.client.request({
                'path': '/drive/v2/files/' + theID,
                'method': 'GET',
            });
            request.execute(function (resp) {
                console.log('Title: ' + resp.title);
                console.log('Description: ' + resp.description);
                console.log('MIME type: ' + resp.mimeType);
                console.log('WebContent: ' + resp.webContentLink);
            });
        }

    </script>





我的尝试:





What I have tried:

using Google.Apis.Drive.v3.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
using ASPSnippets.GoogleAPI;
using System.Web.Script.Serialization;
using Google.Apis.Drive.v3;
using Google.Apis.Services;

using System.Net;


public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        GoogleConnect.ClientId = "----------------";
        GoogleConnect.ClientSecret = "------------";
        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.PostFile(code, (HttpPostedFile)Session["File"], Session["Description"].ToString());
            GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize<GoogleDriveFile>(json);
            tblFileDetails.Visible = true;
            lblTitle.Text = file.Title;
            lblId.Text = file.Id;
            Label1.Text = file.WebContentLink;
           
            imgIcon.ImageUrl = file.IconLink;
            lblCreatedDate.Text = file.CreatedDate.ToString();
            lnkDownload.NavigateUrl = file.WebContentLink;
            if (!string.IsNullOrEmpty(file.ThumbnailLink))
            {
                rowThumbnail.Visible = true;
                imgThumbnail.ImageUrl = file.ThumbnailLink;
            }
        }
        if (Request.QueryString["error"] == "access_denied")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
        }
    }

    protected void UploadFile(object sender, EventArgs e)
    {
        Session["File"] = FileUpload1.PostedFile;
        Session["Description"] = txtDescription.Text;
        GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.file");
    }

    public class GoogleDriveFile
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public string OriginalFilename { get; set; }
        public string ThumbnailLink { get; set; }
        public string IconLink { get; set; }
        public string WebContentLink { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime ModifiedDate { get; set; }
    }
    
    }

}

推荐答案

使用google drive api。

Google Drive Api [< a href =http://www.daimto.com/google-drive-api-c-upload/target =_ blanktitle =新窗口> ^ ]



有一个很好的如何在网站和一个示例项目上实现教程。

只需按照这种方式实现它就可以了。
Use the google drive api for that.
Google Drive Api[^]

There is a good how to implement tutorial on the site and a sample project.
Just implement it that way and you will be good to go.


这篇关于使用javascript从Google云端硬盘获取文件元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆