编写一个应用程序,该应用程序将抓取用户上传的打包 zip 文件的上传目录,并在 Google for Work 共享 google 云端硬盘文件夹中重新创建 zip 内目录结构。
问题:在 For Work 域中创建的服务帐户无法访问或可见共享文件夹。代码是 C# 语言。我希望我只是错过了一些愚蠢的事情。
详细信息:以域管理员帐户登录。进入 google api 控制台,启用 api,创建服务帐户,授予对该服务帐户的电子邮件的访问权限。通过API和服务帐户,在文件对象列表中找不到共享文件夹,也无法通过ID上传到它。
使用共享文件夹的 in-url 文件夹 ID 调用以下代码片段。共享到服务帐户的文件夹不会显示在返回的内容列表中。
// get starting point
string masterParent = "xxxxx"; // pulled from URL after sharing folder
File masterParentFolder = GetGAPIFileById( service, masterParent, false );
Run Code Online (Sandbox Code Playgroud)
示例片段:
static File GetGAPIFileById( gapi.DriveService service, string id, bool folderOnly ) {
if( null == id ) id = "-1";
File rtn = null;
var lreq = service.Files.List();
lreq.MaxResults = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用服务帐户通过 Google 我的商家 API 检索位置/评论。
到目前为止我有:
当使用 Google 的示例 .NET 客户端(可从https://developers.google.com/my-business/sampleshttps://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations下载)以编程方式列出邀请时,我可以看到邀请
但是,当我尝试通过请求接受邀请时,请求https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations/[INVITATION NAME]:accept失败并出现 500 服务器错误。
创建MyBusinessService实例时,我首先创建一个服务帐户凭据,例如:
ServiceAccountCredential credential;
using (Stream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = (ServiceAccountCredential)GoogleCredential
.FromStream(stream)
.CreateScoped(new [] { "https://www.googleapis.com/auth/plus.business.manage" })
.UnderlyingCredential;
}
Run Code Online (Sandbox Code Playgroud)
接下来我创建一个初始化程序,例如:
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My GMB API Client",
GZipEnabled = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 C# 连接到新的 Google Analytics Data api,以从新的 Google Analytics GA4 请求数据。我能找到的唯一示例是 Quickstart 客户端库 .net这确实有效,但它使用服务帐户。云 .net 客户端库google-cloud-dotnet仅包含使用服务帐户的示例。
当我尝试传递桌面应用程序凭据以使用 Oauth”授权时,我得到
从 JSON 创建凭据时出错。无法识别的凭据类型。
using System;
using System.Threading;
using System.Threading.Tasks;
using Google.Analytics.Data.V1Beta;
namespace GoogleAnalyticsExamplesData
{
class Program
{
private const string PropertyId = "250796939";
private const string PathToCreds = @"C:\dev\ServiceAccountCred.json";
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
// Check whether the environment variable exists.
var environmentVariable = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");
// If necessary, create it.
if (environmentVariable == null)
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", PathToCreds); …Run Code Online (Sandbox Code Playgroud) c# google-api google-api-dotnet-client google-analytics-4 google-analytics-data-api
我有一个用 C# 编写的应用程序,因此它可以是一个独立的 .exe,并在运行时通过 cmd 传入参数。我正在尝试更新 google 驱动器中的文件而不更改 fileid,以便使用该 id 的任何链接都不会被破坏。以下代码一直有效,直到使用 Google.Apis.Drive.v3.Data.File updateFile 到达第三部分,其中文件始终为“null”。request.ResponseBody 具有正确的 fileId、正确的路径,并且几乎总是出现空值。
我怎样才能得到它来更新文件?
是否有一些代码更新/更改不再有效?
任何帮助,将不胜感激-
第 1 部分 - 这是调用接下来两部分的代码的开头:
// System Library Requirements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Security;
// Microsoft Library Requirements
using Microsoft.Win32;
// Google API Library Requirements
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using GoogleV2 = Google.Apis.Drive.v2;
using Google.Apis.Drive.v3.Data;
using …Run Code Online (Sandbox Code Playgroud) 我正在构建一个MVC应用程序,它将对我们网站上的用户进行身份验证,这些用户希望我们将事件发布到他们的日历中.我已经安装了.NET C#客户端库以及Auth和MVC包.
使用Google.Apis.Auth.OAuth2.Mvc我无法访问TokenResponse我的实现IDataStore,而是将URL保存为令牌,即localhost:6055/calendar/calendarasync/deantest04556734
我发现的所有示例似乎都已过时,没有使用Mvc包而没有实现DataStore来保存到数据库,因此我使用了daimto示例中的代码和官方示例来开始.
任何人都可以指出我正确的方向或看到我的代码有任何问题?
DatabaseDataStore
public class DatabaseDataStore : IDataStore
{
private SqlConnection connection;
public DatabaseDataStore(SqlConnection sqlConn)
{
if (sqlConn != null)
{
connection = sqlConn;
if(connection.State != ConnectionState.Open)
connection.Open();
}
}
/// <summary>
/// Stores the given value for the given key. It creates a new file (named <see cref="GenerateStoredKey"/>) in
/// <see cref="FolderPath"/>.
/// </summary>
/// <typeparam name="T">The type to store in the data store</typeparam>
/// <param name="key">The key</param>
/// <param name="value">The value …Run Code Online (Sandbox Code Playgroud) 我的机构目前从2009年初开始运行Google Apps for Education.我负责创建,删除,修改学生电子邮件帐户等.我已将所有现有的C#应用程序从GData转换为新的Admin SDK - 生活很美好.
上周,其中一个部门向大约800名学生发送了一封包含错误的电子邮件.我被问到是否可以创建一个能够删除800个学生收件箱的电子邮件的快速应用程序.
使用我的"超级管理员"域帐户,我可以使用Gmail API创建一个应用程序,以进入我的收件箱并选择符合特定条件的特定电子邮件; 示例:from:xxxx@domain.edu AND is:unread AND subject:test 我能够返回消息ID的集合,然后我可以从收件箱中删除它们 - 太棒了!
由于我能够在我的收件箱中执行此操作,因此我认为我会进行另一项测试并插入其中一个800电子邮件地址并获得相同的结果.不幸的是我收到此错误消息:
错误:Google.Apis.Requests.RequestError拒绝委托xxxxx@domain.edu [403]错误[消息[委托被拒绝xxxxx@domain.edu]位置[ - ]原因[禁止]域[全局]]
我确实阅读了有关帐户委派的内容,但这需要从我的"超级管理员"帐户发送请求,并且学生接受该请求.
可能是域名的"超级管理员"在任何收件箱中没有这些权限,除了他们自己的?我试过阅读帖子和谷歌的文档,但我似乎无法找到关于这个主题的答案.
在此桌面应用程序的开发人员控制台中启用了Gmail API.
我正在使用的服务帐户已获得授权,并且在C#应用程序中使用的是正确的范围:
Scopes = new[] {
"https://mail.google.com",
GmailService.Scope.GmailCompose,
GmailService.Scope.GmailInsert,
GmailService.Scope.GmailLabels,
GmailService.Scope.GmailModify,
GmailService.Scope.GmailReadonly,
GmailService.Scope.MailGoogleCom,
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"},
Run Code Online (Sandbox Code Playgroud)
我的C#代码:
List<Google.Apis.Gmail.v1.Data.Message> result = new List<Google.Apis.Gmail.v1.Data.Message>();
UsersResource.MessagesResource.ListRequest request = GoogleToken.GoogleService().Users.Messages.List("xxxxx@domain.edu");
request.Q = " from:xxxx@domain.edu AND is:unread AND subject:test ";
do
{
try
{
ListMessagesResponse response = request.Execute();
result.AddRange(response.Messages);
request.PageToken = response.NextPageToken;
}
catch (Exception eX)
{
Debug.WriteLine("Error: " …Run Code Online (Sandbox Code Playgroud) 我一直在使用Google表格API,并遵循Google指南.然而,除了谷歌的第二页之外,没有任何例子可以添加工作表并在.NET中写入新工作表.有很多js,但我不知道如何1)添加一张或2)写入新表.
我怎样才能做到这一点?现在我能像在例如与出任何问题阅读,我只找到一个其他的参考V4 C#.我尝试回到v3,但所有文档强烈建议使用v4.
有没有人能够做到这一点?以下是我迄今为止所做的一切:
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
// Add new Sheet
string sheetName = string.Format("{0} {1}", DateTime.Now.Month, DateTime.Now.Day);
AddSheetRequest addSheetRequest = new AddSheetRequest();
addSheetRequest.Properties.Title = sheetName;
// How do I tell this to update??
Run Code Online (Sandbox Code Playgroud) 我可以使用.NET快速入门教程访问Google Calendar API ,效果很好!
该教程的问题在于它使用Open Authentication or OAuth2.我想使用服务帐户身份验证执行相同操作.
(https://support.google.com/googleapi/answer/6158857?hl=en)
有人能举例说明如何使用服务帐户密钥文件访问我的日历吗?
我也试过尝试使用带有C#教程的Google Calendar API身份验证,但无法完成它.
c# google-calendar-api google-api google-api-dotnet-client service-accounts
我正在尝试使用Google Drive API v3将文件从一个文件夹移动到另一个文件夹.我在这里找到了文档.我使用了文档页面中的.NET示例代码,并创建了一个如下所示的方法:
public ActionResult MoveFile(string fileToMove, string destination)
{
DriveService service = new DriveService(new BaseClientService.Initializer
{
HttpClientInitializer = <USER CREDENTIAL>,
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 = '" + destination + "'";
string destinationId = searchFiles.Execute().Files[0].Id;
//Code used from documentation
// Retrieve the existing parents to remove
var getRequest = service.Files.Get(fileToMoveId);
getRequest.Fields …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc google-api google-drive-api google-api-dotnet-client
我需要在我使用asp.net Web表单(C#)构建的CMS Web应用程序的仪表板页面中集成来自Google Analytics的非常基本的报告.
我记得我能够在2015年使用API V3进行的测试中做到这一点,但是现在,使用V4,我总是会收到一条错误消息,即验证需要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 = "<<API-KEY>>";
public static void Test()
{
AnalyticsReportingService ars = GetService(vmcApiKey);
// Create the DateRange object.
DateRange dateRange = new DateRange() { StartDate = "2017-01-01", EndDate = "2017-04-28" };
// Create the Metrics object.
Metric sessions = …Run Code Online (Sandbox Code Playgroud) c# asp.net google-api google-analytics-api google-api-dotnet-client