[英]Service Account authentication to upload a file to Google Drive
I need to upload a file to Google Drive from my Web Application. 我需要从Web应用程序将文件上传到Google云端硬盘。 I need to use Service Account authentication.
我需要使用服务帐户身份验证。 I have read Google Drive guide here: DotNetQuickStart and this tutorial for authentication Authentication Google Drive MVC but i don't know what i need to do.
我在这里阅读了Google云端硬盘指南: DotNetQuickStart和本教程进行身份验证身份验证Google Drive MVC,但我不知道该怎么做。
In order to Google Drive guide i have set the parameter to Google Developers Page. 为了使用Google云端硬盘指南,我已将参数设置为Google Developers Page。
I have download and implemented secret.json file to my project and i have add this code to my project: 我已经下载并实现了secret.json文件到我的项目中,并将此代码添加到我的项目中:
public static Google.Apis.Drive.v2.Data.File uploadFile(string _uploadFile, string _parent)
{
string[] scopes = new string[] { DriveService.Scope.Drive }; // Full access
var keyFilePath = @"c:\file.p12"; // Downloaded from https://console.developers.google.com
var serviceAccountEmail = "xx@developer.gserviceaccount.com"; // found https://console.developers.google.com
//loading the Key file
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = scopes
}.FromCertificate(certificate));
But i can't understand what to set in keyFilePath and serviceAccountEmail. 但是我不明白在keyFilePath和serviceAccountEmail中设置什么。 How can i set this code?Thanks to all
我该如何设置此代码?
You will need the P12 key file instead of secret.json 您将需要P12密钥文件而不是secret.json
Go to https://console.developers.google.com/iam-admin/serviceaccounts --> select your project --> click on the 3 vertical dots located at the right side of the listed Service account --> Create key --> you will see the below dialog 转到https://console.developers.google.com/iam-admin/serviceaccounts- >选择您的项目->单击位于列出的服务帐户右侧的3个垂直点->创建密钥- ->您将看到以下对话框
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.