Tag: google api

使用Google凭据登录UWP C#app

我正在尝试登录我正在为一个客户开发的UWP应用程序,该客户端有一个使用G Suite的@.com电子邮件。 它不必访问任何用户数据,他们只是希望它作为身份validation,以便只有拥有公司电子邮件的人才能访问该应用程序。 如果他们可以在不使用网络浏览器的情况下从应用程序内登录,那将会很棒,如果它能记住它们就更好,这样他们就不必每次都登录。 我一直在关注OAuth 2.0和谷歌的其他几个解决方案,但无法真正理解使用哪个,更不用说如何使用。 我查看了这个答案,但使用您的应用程序发送证书文件似乎不是一个好主意。 所以基本上如果可以这样做,我需要从Google获得哪些(如果有的话)证书或凭证,以及如何处理它们以及通过我的C#代码登录? 编辑 该应用程序是100%客户端,没有服务器后端

如何通过Oauth2身份validation使用Google Contacts API

我在下面的代码中使用使用OAuth2的Google Calendar API( https://developers.google.com/google-apps/calendar/ )获取日历条目。 它运作良好。 private IList scopes = new List(); private CalendarService calendarService; private void InitializeCalendarService() { // Add the calendar specific scope to the scopes list scopes.Add(CalendarService.Scopes.Calendar.GetStringValue()); // Display the header and initialize the sample CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader(“Google.Api.Calendar.v3 Sample”); // Create the authenticator //FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials […]

无法加载文件或程序集System.Threading.Tasks,Version = 2.5.19.0

我有一个使用google url shortener API的WPF(.NET 4)项目,我已经通过nugget安装了客户端库https://www.nuget.org/packages/Google.Apis.Urlshortener.v1/1.7.0.25-beta 该应用程序在Visual Studio中工作正常,但一旦发布就抛出exception无法加载文件或程序集System.Threading.Tasks,Version = 2.5.19.0这个以及所有其他程序集都存在于安装文件夹中,并且它随应用程序一起发布。 我搜索了互联网,人们建议手动绑定app.config中的依赖库,它仍然不起作用,因为app.config中已经提到了我的所有依赖库,下面是我的app.config看起来像

如何使用Google.Apis.YouTube.v3和C#将video上传到youtube?

我用C#创建了console应用程序。 这将把Video从本地驱动器upload到youtube 。 我使用此链接在google api中创建了新应用。 我还使用nuget安装了所有必需的packages 。 当我运行我的应用程序时,我收到错误“ 访问被拒绝 ”我无法找到问题。 我在Task Run()方法中遇到错误。 using System; using System.IO; using System.Reflection; using System.Threading; using System.Threading.Tasks; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.Upload; using Google.Apis.Util.Store; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; namespace Google.Apis.YouTube.Samples { /// /// YouTube Data API v3 sample: create a playlist. /// Relies on the Google APIs Client Library […]

使用Json文件进行Google服务帐户身份validation

我一直关注Googles网站上的Oauth2服务帐户文档。 我也一直在挑选Googles .net客户端库,试图让它工作。 我已经到达了计算机的签名阶段。 Google的隐私密钥如下所示 —–BEGIN PRIVATE KEY—–\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDcmuyQC8rwWdPQ\nmIdksgzSJbVWTU5MeUxy+HAap3yut9wR/L6KGMJ4FBYcsPmXN5gQAhErybavGoZG\nfS1X1/PCpPVpTCA4749K8gbvuZg1JEIAqMtmHiBBrJj5l8eiekQc8pd7Pq35H4wi\nJYXAJGwggPcttkLBRi0xZzd+jdwL1st+7zRt8nMao/xFibInBBvKwb/gP4mJxlQg\nnRdGO6zgMk+PLTcA5C+gFyPA4SdkylrLib5CJO9123FgcfTJZJTukeHo1v0EfU+4\n3bK8HBZnOFa4DHH4mXhkhgYMjibv4Sr/WCEoomJJwNN04SbUEdyhgpM2rZ3cvx+4\nsmB0SQflAgMBAAECggEAXZ100+/dL7++zh9cHVQdcrRDzprBplw3H/bjg7wdgftN\n7Wgm5214YQKNG6HSWORjqC9oX/+agZYs8w69xjBDJg9ggU2nwuGOGky4utQ0jiCT\nzbnTjsMsBxKaXBiXxBBEhVBBDjDcHQLRMdBggNgz9lskCYb1rxT7qqJVf2PtxCuZ\nuxw3whLMRHXvKosER12sMQgGB/0+Nk86GWCqPigpfu7Ec92V0ffcSUaq3gjIUD54\n67TduTWaRDQNB+j2yQsWQZnqRv+TvIXOjinAI+pPbvCUovtiTSZAoz3EalsiXQ0l\nUqDVx26uzEJqhB2kzvAeApuW2Nd5EPxUnf48c4xh4QKBgQDw01mEChWyENV5CBKU\nMSfY0rpAPtq7ahHRR458ZKtITDBlqiZLMjydI65Rr1XxpQ3pJZALObMdUhbvCDfm\nu4BY/lCCt+hcdt9IICvVZsgXgvb6M+Fj2IbYZcAnOm4T1Z1D3I+pW5NdK2ALQRiK\nWsGINOqWCB9WRd7nhmb/XwWyjQKBgQDqgWht5laDuLMc4qpj9finY4qmk57eT3KG\npzbVlT3h7kv7j/j6e+6o9psrqdf1PXpu9XZi3bPtPbH1fX9x5pZgJQRMP4FGOURY\nQDkJfiOOSN/8Vl0senqkscT7DSbe2BqyqQlSlTB4BBF29p1wxb5Wz5HH2BvYE2zI\ni9B4WJcAuQKBgADnajCasRYoBgUcSKWRwaqIr/ZJxhxp+4Mjl59T6WiuEIhxKQ+j\nMqMMXT0lQVdU3UaAw5enMcrsYfWnvD37ejHbUoYLFq4yLAhjRobYieu8rByoUTJE\nv8zUJPKAv6UHaj20+D0UgOsanJOuPN9YE93lBPRnN2blgD6yPHS88JKJAoGABFyh\n16F4LH0L/9aLes6BcIOeeZi3VMU/iRelInXjL8eh7CzyYZ5agxQLMNW46ZvaIiQ4\nroAXL6t9GubZrwGt/F3T5aMswWShS87uAKoy+RuL5wKoOwKQM24HDvBgr7ZvULFq\nNfoGa8UPmhneNdHHx4+W05PGeM9rr5NCLmrfbCkCgYA0nMvEDIJvU3KA3S1cQ3fs\nVopRJwqRIFFL1cHTWaEyIsxEh6i/zAUc/habK82dN3/ZDn/XvWY14k7VZPsSdDC9\noVlQj2z8DVO2K99Oxyh0VlthtecW8exjzkIPJL4srOSl/dooQZS/7ZZyaRQU/BLI\nMdzKHlUKKXWcUU+Ko8W4+w\u003d\u003d\n—–END PRIVATE KEY—–\n 清理钥匙 首先,我清理一下钥匙 private const string PrivateKeyPrefix = “—–BEGIN PRIVATE KEY—–“; private const string PrivateKeySuffix = “—–END PRIVATE KEY—–“; /// Converts the PKCS8 private key to RSA parameters. This method uses the Bouncy Castle library. private static RSAParameters ConvertPKCS8ToRSAParameters(string pkcs8PrivateKey) { var base64PrivateKey = pkcs8PrivateKey.Replace(PrivateKeyPrefix, “”).Replace(“\r\n”, […]

如何使用Gmail API检索我的Gmail邮件?

我想要实现的目标: 我正在使用Gmail API ,基本上我想连接到我的GMail帐户来阅读我的电子邮件,INBOX类别,并获取每封邮件的基本信息(标题/主题, 从 , 到 , 日期和发件人)。 问题: 我正在尝试根据自己的需要调整这个用C#编写的Google示例,我正在寻找C#或Vb.Net的解决方案,无论如何。 (请注意,Google会针对不同的用户所示国家/地区显示不同的代码示例,因此该网页的代码可能与每个用户国家/地区的代码不同,Google的逻辑真的很糟糕。) 我在下面的代码中遇到的问题是: 我在lblInbox.MessagesTotal属性中得到一个空值。 msgItem.Raw属性也总是空的。 我还没有发现如何只解析INBOX类别中的消息。 我还没有发现如何确定消息是读还是未读。 我还没有发现如何确定邮件的基本信息(主题,从,到,日期,发件人)。 这是我尝试过的,请注意,在调整Google的示例时,我认为”user”参数应该是Gmail用户帐户名称( “MyEmail@GMail.com” ),但我不确定它应该是。 Imports System.Collections.Generic Imports System.IO Imports System.Linq Imports System.Text Imports System.Threading Imports System.Threading.Tasks Imports Google.Apis.Auth.OAuth2 Imports Google.Apis.Services Imports Google.Apis.Util.Store Imports Google.Apis.Gmail Imports Google.Apis.Gmail.v1 Imports Google.Apis.Gmail.v1.Data Imports Google.Apis.Gmail.v1.UsersResource Public Class Form1 : Inherits Form Private Async […]

请求的客户未经授权

我正在尝试使用google service account从我的域名获取谷歌用户。 但它会引发错误 Error:”access_denied”, Description:”Requested client not authorized.”, Uri:”” 我的代码 X509Certificate2 certificate = new X509Certificate2(key_path, “notasecret”, X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(“publickey.gserviceaccount.com”) { Scopes = scopes, User = “admin@domain.com” }.FromCertificate(certificate)); var service = new DirectoryService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = “appname”, }); service.Users.List().Domain = “domain.com”; Users results = service.Users.List().Execute(); 提前致谢

Google使用服务帐户协调OAuth2

我有一个带有Google Coordinate .Net库和服务帐户开放认证的C#控制台应用程序。 private const string SERVICE_ACCOUNT_EMAIL = “XXX@developer.gserviceaccount.com”; private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @”\YYY-privatekey.p12″; private const string GOOGLE_COORDINATE_TEAM_ID = “ZZZ”; private CoordinateService BuildService() { X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, “notasecret”, X509KeyStorageFlags.Exportable); var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate){ ServiceAccountId = SERVICE_ACCOUNT_EMAIL, Scope = CoordinateService.Scopes.Coordinate.GetStringValue() }; var auth = new OAuth2Authenticator(provider, AssertionFlowClient.GetState); return new CoordinateService(new BaseClientService.Initializer(){ […]

如何以编程方式提供凭据以在c#或vb.net中使用google drive api?

我制作了一个程序,使用谷歌驱动器api从谷歌驱动器上的文件中读取数据。 第一次运行应用程序时,它会打开一个Web浏览器,要求使用google驱动器帐户登录。 我想为应用程序提供用户名和密码,以便自动获取凭据,以便用户无需知道我的Google云端硬盘帐户的用户名和密码。 这是vb.net中的代码: Dim credential As UserCredential Using stream = New FileStream(“client_secret.json”, FileMode.Open, FileAccess.Read) Dim credPath As String = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal) credPath = Path.Combine(credPath, “.credentials/drive-dotnet-quickstart.json”) credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, “user”, CancellationToken.None, New FileDataStore(credPath, True)).Result ‘Console.WriteLine(“Credential file saved to: ” + credPath) End Using //I want to provide the username and password in the […]

c#:google drive:google apis.services你错过了程序集或引用

我正在尝试使用快速启动示例使用google.drive for .net。 我已经通过nuget安装了dll,但是我收到以下错误,我错过了google.apis.service的引用或程序集。 任何帮助,将不胜感激 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Drive.v2; using Google.Apis.Drive.v2.Data; using Google.Apis.Util; using Google.Apis.Services; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { String CLIENT_ID […]