Google PageSpeed API dotnet .net [英] Google PageSpeed API dotnet .net
问题描述
我已经建立了一个基本的C#应用程序,以便在我使用Google.Apis.Pagespeedonline.v2 nuget包指定的网站上运行PageSpeed测试.
I have set up a basic C# application to run a PageSpeed test on a website that I specify using the Google.Apis.Pagespeedonline.v2 nuget package.
设置非常简单,我有一个变量,可以指定随后要传递给服务的网址
The set up is simple enough and I have a variable that I can specify the url which is then past in to the Service
// Create the service.
var service = new PagespeedonlineService(new BaseClientService.Initializer
{
ApplicationName = "PageSpeed Sample",
ApiKey = "[API_KEY_HERE]"
});
var url = "URL_TO_TEST";
// Run the request.
var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();
问题是.Runpagespeed方法仅接受URL.我至少需要指定移动"策略,这样我才能获得台式机和移动设备的得分.我知道这在其他库中也是可能的,但是.NET中似乎缺少它.有人知道使用.NET库执行此操作的方法吗?在参考文档中,它暗示该方法可以接受其他可选参数,但代码中没有.
The problem being the .Runpagespeed method ONLY accepts URL. I need to be able to specify, at minimum, the 'Mobile' strategy so I can obtain scores for both Desktop and Mobile. I know this is possible in other libraries but seems to be missing in .NET. Is anybody aware of a way to do this using the .NET library? In the reference documentation it implies that the method accepts further optional parameters but it does not in the code.
推荐答案
Pagespeedapi: runpagespeed has an optional value called strategy
策略字符串使用的分析策略
strategy string The analysis strategy to use
可接受的值为:
桌面":获取并分析以下网址的网址:
桌面浏览器
移动设备":获取并分析移动设备的URL
设备
Acceptable values are:
"desktop": Fetch and analyze the URL for
desktop browsers
"mobile": Fetch and analyze the URL for mobile
devices
示例:
var request = service.Pagespeedapi.Runpagespeed(url);
request.Strategy = Google.Apis.Pagespeedonline.v2.PagespeedapiResource.RunpagespeedRequest.StrategyEnum.Mobile;
var results = request.Execute();
这篇关于Google PageSpeed API dotnet .net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!