标签: google-api-dotnet-client

使用Google Data API使用C#访问Google Spreadsheets

我在Google Spreadsheets中有一些信息作为单页.有什么办法可以通过提供谷歌凭据和电子表格地址从.NET读取这些信息.是否可以使用Google Data API.最后,我需要从DataTable中获取Google电子表格中的信息.我该怎么做?如果有人尝试过,请分享一些信息.

c# google-sheets google-data-api google-api-dotnet-client google-sheets-api

102
推荐指数
3
解决办法
10万
查看次数

无法加载文件或程序集System.Net.Http.Primitives.位于程序集的清单定义与程序集引用不匹配

我正在开发一个使用Google API的程序.但是,每次运行我的程序时,我都会遇到以下错误:

无法加载文件或程序集'System.Net.Http.Primitives,Version = 1.5.0.0,Culture = neutral,PublicKeyToken = b03f5f711d50a3a'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.

我正在使用Visual Studio 2012 express.我已经尝试过这个链接并浏览了很多论坛,但似乎都没有.主要问题似乎来自我引用的DLL文件"Google.Apis.dll",它引用了System.Net.Http.Primitives v1.5.0.0.但是我的程序引用的版本是2.2.13.0.我尝试使用程序参考v1.5.0.0(我设法找到dll以及Google.Apis的源代码)但是这只引起了另一个问题,我需要一个更新版本的System.Net. Http.Primitives.

我一直在努力找到解决这个问题的方法,但我似乎找不到任何可行的方法.谢谢你的时间.

exception google-api-dotnet-client

66
推荐指数
5
解决办法
5万
查看次数

适用于.NET的Analytics Reporting API V4客户端库

我正在尝试从我们的Google分析实例中获取一些数据,并且我想使用适用于.NET的Analytics Reporting API V4客户端库(https://developers.google.com/api-client-library/dotnet/apis/analyticsreporting/v4)这样我就可以将一些数据烘焙到我们构建的管理站点中.我无法找到使用此代码的任何示例,文档似乎非常稀疏.我想使用服务帐户进行授权,因为我们只需要查看与我们控制的分析帐户相关联的数据.

如果有人能提供一些示例代码或指出我正确的方向使用.net api获取一些基本的报告数据,我将不胜感激

.net c# google-analytics-api google-api-dotnet-client google-analytics-firebase

36
推荐指数
3
解决办法
2万
查看次数

是否可以使用json密钥而不是p12密钥来获取服务帐户凭据?

我在C#中使用"Google.Apis.Bigquery.v2客户端库".

我使用"服务帐户"授权Google BigQuery(请参阅http://www.afterlogic.com/mailbee-net/docs/OAuth2GoogleServiceAccounts.html).要创建X509证书,请使用Google Developers Console中的p12密钥.但是,现在json键是默认值.我可以用它代替p12键吗?

我有以下代码:

    string serviceAccountEmail = "xxxx@developer.gserviceaccount.com";

X509Certificate2 certificate;
using (Stream stream = new FileStream(@"C:\key.p12", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    using (MemoryStream ms = new MemoryStream())
    {
        stream.CopyTo(ms);
        certificate = new X509Certificate2(ms.ToArray(), "notasecret", X509KeyStorageFlags.Exportable);
    }
}

// Create credentials
ServiceAccountCredential credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[] {
        BigqueryService.Scope.Bigquery,
        BigqueryService.Scope.CloudPlatform,
    },
    }.FromCertificate(certificate));

// Create the service
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "My Application",
    GZipEnabled = true,
}; …
Run Code Online (Sandbox Code Playgroud)

c# google-bigquery google-api-dotnet-client google-sheets-api

25
推荐指数
1
解决办法
7631
查看次数

Google .NET API - 除FileDataStore之外的任何其他DataStore?

我正在使用Google .NET API从谷歌分析中获取分析数据.

这是我开始身份验证的代码:

IAuthorizationCodeFlow flow =
    new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
        {
            ClientSecrets = new ClientSecrets
            {
                ClientId = googleApiClientId,
                ClientSecret = googleApiClientSecret
            },
            Scopes = new[] { 
                Google.Apis.Analytics.v3.AnalyticsService.Scope.AnalyticsReadonly
            },
            DataStore = new Google.Apis.Util.Store.FileDataStore("Test_GoogleApi")
        });
Run Code Online (Sandbox Code Playgroud)

它使用FileDataStore作为文件存储在本地用户配置文件中.我在ASP.NET应用程序中运行此代码,因此我无法真正使用该FileDataStore,因此我需要的是获取数据的其他方法.

Google.Apis.Util.Store仅包含FileDataStore和IDataStore的接口.在我开始实现自己的DataStore之前 - 是否还有其他可供下载的DataStore对象?

谢谢

c# asp.net asp.net-mvc google-api google-api-dotnet-client

24
推荐指数
3
解决办法
2万
查看次数

如何使用C#中的服务帐户登录Google API - 凭据无效

我试图通过简单的服务帐户登录来使用C#,Google API和Google Analytics(分析)来打败自己.我的公司已经将数据导入到Analytics中,我可以使用他们的查询资源管理器查询信息,但是.Net的入门不会随处可见.我正在使用谷歌生成的带有PKI的json文件,因为文档说这样的服务帐户是与Googla API进行计算机到计算机通信的正确方法.代码snipet:

public static GoogleCredential _cred;
public static string _exePath;

static void Main(string[] args) {
    _exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace(@"file:\", "");
    var t = Task.Run(() => Run());
    t.Wait();
}

private static async Task Run() {
    try {
        // Get active credential
        using (var stream = new FileStream(_exePath + "\\Default-GASvcAcct-508d097b0bff.json", FileMode.Open, FileAccess.Read)) {
            _cred = GoogleCredential.FromStream(stream);
        }
        if (_cred.IsCreateScopedRequired) {
        _cred.CreateScoped(new string[] { AnalyticsService.Scope.Analytics });
        }
        // Create the service
        AnalyticsService service = new AnalyticsService(
            new BaseClientService.Initializer() {
                HttpClientInitializer = _cred, …
Run Code Online (Sandbox Code Playgroud)

c# google-analytics-api google-oauth google-api-dotnet-client service-accounts

24
推荐指数
4
解决办法
2万
查看次数

ASP.net应用程序崩溃 - 无法加载文件或程序集'Microsoft.Threading.Tasks.Extensions.Desktop'

我想使用OAuth2和.Net 4.5框架构建一个Google BigQuery C#ASP.net应用程序.我运行了这些NuGet安装

Install-Package Google.Apis.Bigquery.v2 -Pre
Install-Package Google.Apis.Authentication.OAuth2 -Version 1.2.4696.27634

Install-Package Google.Apis -Pre
Install-Package Google.Apis.Auth -Pre
Run Code Online (Sandbox Code Playgroud)

我将相关的"使用"放在代码隐藏文件"default.aspx.cs"中:

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Bigquery.v2;
using Google.Apis.Bigquery.v2.Data;

namespace BigQueryDemoApp
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserCredential credential;
            FileStream stream;

            using (stream = new FileStream(
                    Server.MapPath("~/client_secrets.json"),
                    FileMode.Open, FileAccess.Read)
                )
            {
                GoogleWebAuthorizationBroker.Folder =
                    "Tasks.Auth.Store";
                credential = GoogleWebAuthorizationBroker.
                    AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] …
Run Code Online (Sandbox Code Playgroud)

.net asp.net google-api-dotnet-client

18
推荐指数
1
解决办法
2万
查看次数

Google API Oauth2:所有用户只能使用一个刷新令牌吗?

我正在使用OAuth2身份验证,我有一个拥有多个用户的CMS,每个用户都有自己的配置文件.我们公司的Google帐户可以访问多个Google Analytics帐户.对于使用CMS的每个用户,我使用不同的用户名连接到Google AnalyticsAPI,每个用户的令牌都保存在数据库数据存储中.问题是,如果一个用户断开连接并撤消其令牌,则使用相同Google帐户的其他任何用户都无法访问Analytics API,这没有任何意义.

在此输入图像描述

编辑:经过进一步调查,我发现当第一个用户进行身份验证时,保存在数据存储中的令牌包含'refresh_roken'和'access_token'.但是,当其他用户进行身份验证时(他们使用相同的Google帐户,但使用不同的Google Analytics帐户),他们的令牌只会包含"access_token".如果其中一个人撤销了他的令牌,他们就会失去联系.

如何阻止这种情况发生并让每个用户都收到自己的refresh_token?


编辑2:

我在数据存储中存储单独的行,每个用户一个.让我澄清一下 - 如果你看一下这个图,想象一个CMS,其中一个CMS用户需要查看"Liz的个人账户"的统计数据,另一个CMS用户需要查看"Liz的团队账户"的统计数据.

两个CMS用户都来自同一家公司,他们都使用相同的Google帐户 - "liz@gmail.com".CMS用户A使用"liz@gmail.com"连接到Analytics API,收到refresh_token并想查看"Liz网站"的统计信息.然后CMS用户B也使用"liz@gmail.com"连接到Analytics API,但现在他不再收到refresh_token,只有access_token - 这是一个问题,因为在access_token之后将再次要求用户连接到期.

当一个用户断开连接时我通常做的是从数据存储中删除令牌并撤销令牌,但是我可能不应该撤销它,是吗?在任何情况下,如果在我的场景中用户A断开连接,这将删除他的数据存储令牌,这意味着我们将不再存储refresh_token,因为用户B首先没有它.

用户帐户图: 用户帐户图

c# google-api google-analytics-api google-api-dotnet-client google-oauth2

15
推荐指数
2
解决办法
2195
查看次数

使用C#和Sheets API v4更新Cell

有没有人有一个很好的C#示例用于使用v4 API更新单元格?

我在使用Google表格API v4的开发者网站上获得了获取单元格值c#示例.我试图修改示例以更新值为"Tom"的单元格.我坚持设置SpreadSheets.Values.Update.

using Google.Apis.Auth.OAuth2;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GoogleSheetsAPI4_v1console
    {
    class Program
    {
        // If modifying these scopes, delete your previously saved credentials
        // at ~/.credentials/sheets.googleapis.com-dotnet-quickstart.json
        static string[] Scopes = { SheetsService.Scope.Spreadsheet };
        static string ApplicationName = "TestSpreadsheet";

        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = …
Run Code Online (Sandbox Code Playgroud)

c# google-api google-sheets google-api-dotnet-client google-sheets-api

15
推荐指数
2
解决办法
2万
查看次数

我可以在OAuth 2.0中使用Chrome网上应用店付款吗?

我编写了一个托管的Chrome网络应用程序,该应用程序使用适用于.NET的Google API客户端库对使用OAuth 2.0的用户进行身份验证.现在,我想使用内置的Chrome网上应用店付款向我们的应用添加付款.

查看文档时,我需要一个OpenID URL来检查付款.

如何使用OAuth而不是OpenID身份验证来获取此UserID/OpenID URL?

var service = new Google.Apis.Oauth2.v2.Oauth2Service(
    new BaseClientService.Initializer
    {
        HttpClientInitializer = userCredential,
        ApplicationName = "My App Name",
    }
);
HttpResponseMessage message = await service.HttpClient.GetAsync(
    string.Format("https://www.googleapis.com/chromewebstore/v1/licenses/{0}/{1}", 
        appId,
        fedId // Where do I get this??
    )
);
Run Code Online (Sandbox Code Playgroud)

c# google-oauth google-chrome-app google-api-dotnet-client

14
推荐指数
1
解决办法
589
查看次数