Google PageSpeed API dotnet .net

孤者浪人 提交于 2019-12-10 17:55:39

问题


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();

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.


回答1:


Pagespeedapi: runpagespeed has an optional value called strategy

strategy string The analysis strategy to use

Acceptable values are:
"desktop": Fetch and analyze the URL for desktop browsers
"mobile": Fetch and analyze the URL for mobile devices

Example:

 var request = service.Pagespeedapi.Runpagespeed(url);
 request.Strategy = Google.Apis.Pagespeedonline.v2.PagespeedapiResource.RunpagespeedRequest.StrategyEnum.Mobile;
 var results = request.Execute();


来源:https://stackoverflow.com/questions/34291450/google-pagespeed-api-dotnet-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!