小编Phi*_*ins的帖子

Azure上的Google Analytics Api

我想在我的MVC网站上使用google analytics api,使用api服务帐户进行身份验证,oauth2在我的localhost上没有问题,但是一旦我部署到Azure,我就会收到502错误:

"502 - Web服务器在充当网关或代理服务器时收到无效响应.您正在查找的页面存在问题,无法显示.当Web服务器(充当网关或代理)时联系在上游内容服务器上,它收到了来自内容服务器的无效响应."

继承我的代码:

const string ServiceAccountUser = "xxxxxxxxxx-cpla4j8focrebami0l87mbcto09j9j6k@developer.gserviceaccount.com";
AssertionFlowClient client = new AssertionFlowClient(
        GoogleAuthenticationServer.Description,
            new X509Certificate2(System.Web.Hosting.HostingEnvironment.MapPath("/Areas/Admin/xxxxxxxxxxxxxxxxxx-privatekey.p12"), 
                "notasecret", X509KeyStorageFlags.Exportable))
        {
            Scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue(),
            ServiceAccountId = ServiceAccountUser //Bug, why does ServiceAccountUser have to be assigned to ServiceAccountId
            //,ServiceAccountUser = ServiceAccountUser
        };
        OAuth2Authenticator<AssertionFlowClient> authenticator = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚是什么造成的?我在Azure中遗漏了什么?

谢谢你的帮助.

c# asp.net-mvc azure google-analytics-api oauth-2.0

7
推荐指数
2
解决办法
1778
查看次数

C#简写LINQ.所以声明

只是有点困惑如何实现这一点.

我有网站和用户生成的类别,我想返回相关用户生成类别的项目,如果有一个是活动的.所以如果选择了一个类别,但是如果类别为nu​​ll,那么我可以使用它,因为没有对象可以获取isActive属性.

var item = User.Items.Where(x => x.Categoires.FirstOrDefault(s => !s.isSystem).isActive)
Run Code Online (Sandbox Code Playgroud)

所以我只需要检查第一个或默认是否为空,任何帮助将非常感激.

谢谢

c# linq

5
推荐指数
1
解决办法
1954
查看次数

标签 统计

c# ×2

asp.net-mvc ×1

azure ×1

google-analytics-api ×1

linq ×1

oauth-2.0 ×1