Google是否提供对移动设备友好测试的API访问权限?

时间:2015-04-02 21:27:25

标签: google-api

是否有API可以访问Google的移动友好测试,可以在https://www.google.com/webmasters/tools/mobile-friendly/看到?

4 个答案:

答案 0 :(得分:2)

如果你用谷歌搜索找不到它,它可能不存在。

一个hacky解决方案是创建一个PhantomJS进程,该进程输入url,提交它,并对dom进行脏检查以获得结果。

  

PhantomJS是一个带有JavaScript API的无头WebKit脚本。

但是,如果您滥用此功能,Google可能会将您的IP地址列入黑名单。光线使用应该没问题。另请注意,Google可以随时更改其dom结构或类名,因此如果您的工具突然中断,请不要感到惊讶。

这是一些粗略的,未经测试的代码......

var url = 'https://www.google.com/webmasters/tools/mobile-friendly/';
page.open(url, function (status) {

  // set the url
  document.querySelector('input.jfk-textinput').value = "http://thesite.com";
  document.querySelector('form').submit();

  // check for results once in a while
  setInterval(function(){
    var results = getResults(); // TODO create getResults
    if(results){
      //TODO save the results
      phantom.exit();
    }
  }, 1000);
});

答案 1 :(得分:1)

pagespeed api

中有一个选项
https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?url={url}&key={api key}

密钥可以从谷歌云平台获得。

答案 2 :(得分:0)

https://console.developers.google.com/apis/api/pagespeedonline-json.googleapis.com/overview?project=citric-program-395&hl=pt-br&duration=P30D中获取PageSpeed Insights API KEY并创建凭据,按照Google的说明进行操作。

在C#(6.0)和.NET 4.5.2中,我做了一些这样的事情: (在项目中添加Newtonsoft.Json的参考。)

String yourURL = "https://www.google.com.br";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://www.googleapis.com");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync($"/pagespeedonline/v3beta1/mobileReady?url={yourURL }&key=AIzaSyArsacdp79HPFfRZRvXaiLEjCD1LtDm3ww").Result;
string json = response.Content.ReadAsStringAsync().Result;
JObject obj = JObject.Parse(json);
bool isMobileFriendly = obj.Value<JObject>("ruleGroups").Value<JObject>("USABILITY").Value<bool>("pass");

答案 3 :(得分:0)

Mobile Friendly-Test有一个API(Beta)。 (发布日期:2017年1月31日)。

API测试输出有三种状态:

  1. MOBILE_FRIENDLY_TEST_RESULT_UNSPECIFIED运行此测试时出现内部错误。请再次尝试运行测试。
  2. MOBILE_FRIENDLY该页面适合移动设备使用。 3.NOT_MOBILE_FRIENDLY页面不适合移动设备。
  3. 以下是更多信息:https://developers.google.com/webmaster-tools/search-console-api/reference/rest/v1/urlTestingTools.mobileFriendlyTest/run

相关问题