Tag: 谷歌的API,DOTNET客户端

如何将访问令牌从.NET(代码隐藏)传递给Javascript

我想通过.NET框架“授权”使用我自己的API密钥,秘密和刷新令牌,然后将访问令牌传递给JavaScript,这样我就可以使用进度指示器将video直接上传到YouTube。 我有通过.NET API工作的代码 ,可以直接上传到我的频道[未经授权],但你没有进度指示(可能需要一段时间),文件必须先上传到我的服务器,然后到YouTube服务器。 服务器端访问代码是否与客户端访问代码不同? 如果不: 如何获取访问代码服务器端? (得到字符串) ***如何通过JavaScript将其传递给Google API? (不是如何写但在哪里传入它?) 我很清楚暴露访问令牌的安全风险,但这些确实会过期吗? (作为奖励,我如何缩短过期时间)。 这也是在受密码保护的网页内完成的,您没有获得“客户端密码”或“刷新令牌” ***更新 – 我想我在MediaUploader对象中找到了传递令牌的MediaUploader 。 var uploader = new MediaUploader({ baseUrl: ‘https://www.googleapis.com/upload/youtube/v3/videos’, file: selectedFile, token: token, // ***RIGHT HERE*** metadata: metadata, params: params, onError: function(data) {

Google Calendar API – 不从Execute()返回C#

运行下面的代码永远不会从Execute函数返回。 我在个人Gmail帐户上有一个私人日历,我与developer.gserviceaccount.com帐户共享。 查看API管理器,使用/引用显示我已经使用过甚至命中过api。 任何想法都赞赏。 using System.Security.Cryptography.X509Certificates; using System.Web; using Google.Apis.Calendar.v3; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; public class GoogleLoginWithServiceAccount { public string getEventList() { var GoogleOAuth2CertificatePath = HttpContext.Current.Server.MapPath(“~/xx/xx.p12”); var GoogleOAuth2EmailAddress = “xx-xxxx@developer.gserviceaccount.com”; var GoogleOAuth2PrivateKey = “notasecret”; var certificate = new X509Certificate2(GoogleOAuth2CertificatePath, GoogleOAuth2PrivateKey, X509KeyStorageFlags.Exportable); var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(GoogleOAuth2EmailAddress) { //User = GoogleAccount, Scopes = new […]

NativeApplicationClient不受支持

在我的Visual Stuidio Win表单项目中使用此代码时。 var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret); 我收到了一条消息 不再支持NativeApplicationClient,它将在1.7.0-beta中删除。 考虑使用支持.NET 4,.NET for Windows Store应用程序,Windows Phone 7.5和8以及便携式类库的新Google.Apis.Auth NuGet软件包 我在用 install-package Google.Apis.Authentication -pre 如果我添加Google.apis.auth而不是Google.Apis.Authentication它甚至没有NativeApplicationClient。 但我无法找到任何有关我使用NativeApplicationClient的内容的信息。

使用API​​密钥分析报告v4

我需要在我使用asp.net Web表单(C#)构建的CMS Web应用程序的仪表板页面中集成来自Google Analytics的非常基本的报告。 我记得我能够在2015年使用API​​ V3进行的测试中做到这一点,但是现在,使用V4,我总是会收到一条错误消息,即validation需要OAuth2。 我需要访问我拥有的特定分析帐户,而不是在CMS中导航的用户帐户! 因此,我使用Google API Manager提供的API KEY。 我已经给了API Key所有权限。 API密钥类似于:“d471c3ce04612f143ff0Be319aac2e17d0159add” 这是代码 using Google.Apis.AnalyticsReporting.v4; using Google.Apis.Services; using System; using Google.Apis.AnalyticsReporting.v4.Data; using System.Collections.Generic; using System.Threading.Tasks; using System.IO; using Google.Apis.Auth.OAuth2; using System.Threading; using Google.Apis.Util.Store; using System.Web; public static class GoogleAnalyticsAPI { static string vmcApiKey = “<>”; public static void Test() { AnalyticsReportingService ars = […]

谷歌日历Api在本地工作正常但不提高其在服务器上的身份validation

我在console.developers.google.com创建了一个项目以使用Google Calendar API 。 我们需要生成凭证并选择应用程序类型 对于Localhost和应用程序类型, other以下是Json工作正常。 { “installed”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxx-00000”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxx”, “redirect_uris”: [ “urn:ietf:wg:oauth:2.0:oob”, “http://localhost” ] } } 对于应用程序类型Web Application在服务器上托管少数参数在Json具有不同的值,如下所示。 { “web”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxxxx-99999”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxxxxxxxxxxxxx”, “redirect_uris”: [ “http://demo.mydemo.com” ], “javascript_origins”: [ “http://demo.mydemo.com” ] } […]

Powershell Cmdlet缺少组装Google Api

只在尝试创建Powershell Cmdlet时遇到问题。 我可以在控制台应用程序中的进程记录中执行相同的代码。 想法是App.config没有重定向程序集,但没有太大的成功使其工作。 我使用nuget包来引用Google-api-dotnet-client 示例代码在这里 http://tinyurl.com/mbx3yle 错误 http://sofzh.miximages.com/c%23/xiEjwAR.png Get-GAppsUsers : Could not load file or assembly ‘System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified. PsTest.cs using System.ComponentModel; using System.Collections.Generic; using Google.Apis.Admin.Directory.directory_v1.Data; using System.Management.Automation; using System; using Google.Apis.Admin.Directory.directory_v1; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Services; using Google.Apis.Util; using […]

使用Google API for .NET访问用户信息

我正在使用Google API Preview(1.7.0)通过OAuth2授权用户。 我一直在关注示例MVC代码 。 这是我对FlowMetadata实现: private static readonly IAuthorizationCodeFlow flow = …; // Implementation of tokens public static async Task GetCredentials(Controller controller, CancellationToken cancellationToken) { var result = await new AuthorizationCodeMvcApp(controller, new Models.Generic.AppFlowMetadata()).AuthorizeAsync(cancellationToken); if (result.Credential != null) { // Struggling here. How do I make a request to get the e-mail address? } } […]

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 […]