Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google PageSpeed API dotnet .net

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.

like image 506
Hooky17 Avatar asked Feb 08 '23 07:02

Hooky17


1 Answers

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();
like image 144
DaImTo Avatar answered Feb 15 '23 11:02

DaImTo