Tag: 谷歌的API,DOTNET客户端

NativeApplicationClient和OAuth2Authenticator未解析

我正在编写一个控制台应用程序来从BigQuery下载数据。 再一次,.NET库是模糊和混乱的。 在这个问题中 , 两名Google员工发布了一个回复,但我的机器上没有任何响应正在进行,因为他们还没有明确说明他们正在使用哪些参考。 我再次粘贴代码并详细说明: using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Bigquery.v2; using Google.Apis.Util; { public class Program { public static void Main(string[] args) { // Register an authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); // Put your client id and secret here (from https://developers.google.com/console) // Use the installed app flow here. provider.ClientIdentifier = […]

错误:redirect_uri_mismatch在MVC应用程序中的Google登录

我正在尝试通过MVC C#应用程序将video上​​传到YouTube。 我正在关注此链接 每当我尝试运行该应用程序时,我都会收到来自Google的错误。 错误:redirect_uri_mismatch 请求中的重定向URI http:// localhost:52271 / authorize /与授权给OAuth客户端的URI不匹配。 访问https://console.developers.google.com/apis/credentials/oauthclient/CCC-XXX.apps.googleusercontent.com?project=XXXX以更新授权的重定向URI。 这是我的Json文件。 这是我的Google控制台应用程序: 错误: 有什么不对的吗 ? 谢谢。

使用Google Drive API v3移动文件

我正在尝试使用Google Drive API v3将文件从一个文件夹移动到另一个文件夹。 我在这里找到了文档。 我使用了文档页面中的.NET示例代码,并创建了一个如下所示的方法: public ActionResult MoveFile(string fileToMove, string destination) { DriveService service = new DriveService(new BaseClientService.Initializer { HttpClientInitializer = , ApplicationName = “APPNAME” }); var searchFiles = service.Files.List(); searchFiles.Corpus = FilesResource.ListRequest.CorpusEnum.User; searchFiles.Q = “name = ‘” + fileToMove + “‘”; searchFiles.Fields = “files(*)”; string fileToMoveId = searchFiles.Execute().Files[0].Id; searchFiles.Q = “name = ‘” […]

更改Google云端硬盘中的重定向url – C#(第2部分)

我不知道为什么,但这个消息被主持人在我的第一个问题中删除,主持人写道我需要打开新问题。 所以……(第1部分 – 更改Google默认的Auth重定向 – C#(Google liblary) ) 我尝试不好有问题:如果我尝试这个代码: public class MyNewAuthorizationCodeMvcApp : AuthorizationCodeMvcApp { public MyNewAuthorizationCodeMvcApp(Controller controller, FlowMetadata flowData) : base(flowData.Flow, “http://www.yandex.ru”, controller.Request.Url.ToString()) { } } 我得到的错误是:AuthorizationCodeMvcApp构造函数(默认liblary)不会对带有3个参数的构造函数进行竞争 如果我尝试: public class MyNewAuthorizationCodeMvcApp : AuthorizationCodeWebApp { public MyNewAuthorizationCodeMvcApp(Controller controller, FlowMetadata flowData) : base(flowData.Flow, “http://www.yandex.ru”, controller.Request.Url.ToString()) { } } 我没有得到错误但是! 我不能设置Valeu this.controller = controller; this.flowData = flowData; […]

如何在MVC中解析’访问令牌已过期,但我们无法刷新它’

我目前正致力于谷歌Api ,旨在获得一个登录人员的圈子。我已经拥有访问令牌,但问题是每当我尝试运行我的代码时它返回此exception 访问令牌已过期但我们无法刷新它 我该如何解决这个问题? var claimsforUser = await UserManager.GetClaimsAsync(User.Identity.GetUserId()); var access_token = claimsforUser.FirstOrDefault(x => x.Type == “urn:google:accesstoken”).Value; string[] scopes = new string[] {PlusService.Scope.PlusLogin, PlusService.Scope.UserinfoEmail, PlusService.Scope.UserinfoProfile}; var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = “xx-xx.apps.googleusercontent.com”, ClientSecret = “v-xx”, }, Scopes = scopes, DataStore = new FileDataStore(“Store”), }); var token = […]

Google Calendar API v3 – 在服务器上部署时请求超时

我试图登录localhost,一切正常。 代码: public static bool LoginGoogleCalendar(string clientId, string clientSecret, string idGCalendarUser, string calendarServiceScope, string folder) { try { UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret, }, new[] { calendarServiceScope }, idGCalendarUser, CancellationToken.None, new FileDataStore(folder)).Result; return true; } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return false; } } (我正确设置了fileDataStore的授权) 在Google Developers […]

如何正确validation适用于.NET的YouTube v3 Google API的Google帐户

我四处搜索,相关文档已过时(此处的页面显示了早期版本的Google .net apis的示例: https : //developers.google.com/youtube/v3/code_samples/dotnet ) 我正在尝试创建一个可恢复上传到YouTube的应用程序。 我的应用程序已在Google API控制台上注册,并具有我的客户机密和客户端ID。 这是我用来validation的方法: UserCredential credential; using (FileStream stream = new FileStream(“client_secrets.json”, FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload }, “[my_username]”, CancellationToken.None, new FileDataStore(“YouTube.ListMyLibrary”)); } 该过程在等待呼叫时挂起。 client_secrets.json文件加载正常(单独测试)。 但是,当调用AuthorizeAsync时,我会在挂起之前获得以下输出: A first chance exception of type ‘System.IO.FileNotFoundException’ occurred in mscorlib.dll A first chance exception of […]

找不到方法:’Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)’

我已经被困在这几天了。 我复制了google api示例中的确切代码,以便将文件上传到Google云端硬盘。 这是代码 UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = ClientId, ClientSecret = ClientSecret, }, new[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile }, “user”, CancellationToken.None, new FileDataStore(“MyStore”)).Result; 但它会在运行时抛出一个exception:找不到方法:’Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)’。 我已经添加了必要的Google Api dll。 或者,如果有人可以在实施服务器端授权的网站上建议更好的代码将文件上传到Google云端硬盘。 任何帮助将不胜感激。 更新:我将我的代码更改为此 var token = new TokenResponse { RefreshToken = “1/6hnki1x0xOMU4tr5YXNsLgutzbTcRK1M-QOTEuRVxL4” }; var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = […]

由json私钥文件(ServiceAccount)创建的GoogleCredential – 如何设置用户模拟?

刚开始使用Google Apis。 在我的Google Cloud Platform帐户中,我为域范围委派创建了一个服务帐户。 我为此服务帐户保存了json格式的私钥文件。 在我的测试应用程序中,我正在创建一个GoogleCredential实例: var credential = GoogleCredential.FromStream(new FileStream(“privatekey.json”, FileMode.Open, FileAccess.Read)) .CreateScoped(Scopes); 如何设置我想要冒充的用户? 使用p12私钥时,我可以执行以下操作: var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(“xxx@developer.gserviceaccount.com”) //service Account id { Scopes = Scopes, User = “admin@xxx.com” //the user to be impersonated }.FromCertificate(new X509Certificate2(@”xxx.p12″, “notasecret”, X509KeyStorageFlags.Exportable))); 但是,我如何使用GoogleCredential和json privatkey文件“轻松实现”? 亲切的问候

Google API:Gmail服务推送通知(观察) – 未授权用户执行此操作

我想在邮箱上调用watch()。 我设置了一个服务Iam帐户,并创建了一个主题和suscription。 我向我的服务帐户授予了我的主题和订阅的完整(所有者)权限。 但是当在watch()上调用execute时,我收到错误: Google.Apis.Requests.RequestError Error sending test message to Cloud PubSub projects/projectid/topics/topicname : User not authorized to perform this action. [403] Errors [ Message[Error sending test message to Cloud PubSub projects/projectid/topics/topicname : User not authorized to perform this action.] Location[ – ] Reason[forbidden] Domain[global] ] 这是我用来设置服务的代码: credential = new X509Certificate2(“file.p12”), “password”, X509KeyStorageFlags.Exportable); var service […]