I'm trying to establish connection to google cloud for media upload
我正在尝试建立与谷歌云的连接以进行媒体上传
I've used various methods like Setting environment variable, saving json to mongodb , tried directly load json from file and then loading to google functions
我已经使用了各种方法,如设置环境变量,将json保存到mongodb,尝试直接从文件加载json然后加载到google函数
libraries:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using DAL;
using MongoDB;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Configuration;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using System.Drawing;
using Newtonsoft.Json;
using MongoDB;
using MongoDB.Driver.Builders;
using MongoDB.Bson;
Method 1: Using Environment Variable.
方法1:使用环境变量。
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS","onfer-gc.json");
var Credential1 = GoogleCredential.GetApplicationDefaultAsync();
Error : Using Environment Variable.
Error reading credential file from location onfer-gc.json: Error deserializing JSON credential data.
Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS
请检查环境变量GOOGLE_APPLICATION_CREDENTIALS的值
Method 2: Load json from file
方法2:从文件加载json
FileStream stream1 = File.OpenRead("onfer-gc.json");
var Credential = GoogleCredential.FromStream(stream1);
Error deserializing JSON credential data.
Method 3: Loading data from Mongodb database and then trying to turn into string
方法3:从Mongodb数据库加载数据,然后尝试转换为字符串
var Db = new Database();
var result = Db.GetCollection<company>().FindOne(Query.EQ("type", "service_account"));
var Credential = GoogleCredential.FromJson(result);
In this case it gives error
在这种情况下,它会给出错误
Element 'type' does not match any field or property of class MongoDB.company.
Even I've checked solutions onlinehttps://github.com/google/google-api-dotnet-client/issues/747
即使我已经在线检查过解决方案https://github.com/google/google-api-dotnet-client/issues/747
But it didn't work. What am i doing wrong here ?
但它没有用。我在这做错了什么?
1 个解决方案
#1
0
I was successfull establishing connection using Method 2:
我使用方法2成功建立连接:
string credPath = "D:\\Admin\\gcloudcred.json";
var credential = GoogleCredential.FromStream(File.OpenRead(credPath));
var storageClient = StorageClient.Create(credential);
listvideos = storageClient.ListObjects("bucketname");
if (listvideos == null)
{
return listvideos = listvideos1;
}
return listvideos;
#1
0
I was successfull establishing connection using Method 2:
我使用方法2成功建立连接:
string credPath = "D:\\Admin\\gcloudcred.json";
var credential = GoogleCredential.FromStream(File.OpenRead(credPath));
var storageClient = StorageClient.Create(credential);
listvideos = storageClient.ListObjects("bucketname");
if (listvideos == null)
{
return listvideos = listvideos1;
}
return listvideos;