剛開始使用Google Apis。 在我的Google雲端平臺帳戶中,我爲域範圍委派創建了一個服務帳戶。我爲此服務帳戶保存了json格式的私鑰文件。由json私鑰文件(ServiceAccount)創建的GoogleCredential - 如何設置用戶模擬?
在我的測試應用程序我創建一個GoogleCredential實例:
var credential =
GoogleCredential.FromStream(new FileStream("privatekey.json", FileMode.Open, FileAccess.Read))
.CreateScoped(Scopes);
我怎麼可以設置我想冒充用戶? 當使用P12私鑰我能做到以下幾點:
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("[email protected]") //service Account id
{
Scopes = Scopes,
User = "[email protected]" //the user to be impersonated
}.FromCertificate(new X509Certificate2(@"xxx.p12", "notasecret", X509KeyStorageFlags.Exportable)));
但我怎麼能做到這一點「的簡單方法」與GoogleCredential和JSON privatkey文件?
親切的問候
但我想使用.net包裝API。我試圖避免直接的休息電話。 – ReneDev