API call for user count in Chrome Web Store? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-30 13:22:47

This is no such API.

You can use Google Analytics inside an extension to track users manually.

If you don't need anything fancy, just a number of installs and users, there is My Extensions extension, it will track those numbers for you.

flo

Copy and paste the snippet below wherever you want in the body of a html document saved with a ".php" extension.

<?php

//URL of your extension
$url = "https://chrome.google.com/webstore/detail/ddldimidiliclngjipajmjjiakhbcohn";

//Get the nb of users
$file_string = file_get_contents($url);
preg_match('#>([0-9,]*) users</#i', $file_string, $users);
$nbusers = str_replace(",", "",$users[1]);

echo $nbusers; //Display the number of users

?>

You can also do this client-side only (at least on your end) by using a cross-domain tool. This snippet will grab the number of users displayed on the Chrome webstore page for an extension (up-to-date as of April 28, 2018):

var chromeExtensionWebstoreURL = 'https://chrome.google.com/webstore/detail/background-image-for-goog/ehohalpjnnlcmckljdflafjjahdgjpmh';

$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent(chromeExtensionWebstoreURL) + '&callback=?', function(response){
    var numUsers = ((""+response.contents.match(/<span class="e-f-ih" title="([\d]*?) users">([\d]*?) users<\/span>/)).split(",")[2]);
    console.log(numUsers);
});

In the future, Google may change the class name of the user count span, in which case you just need to update the regex appropriately.

Actually there IS some Chrome webstore API. https://developer.chrome.com/webstore/using_webstore_api

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