3

I want to generate some stats myself exclusively concerning my profile. For that purpose I chose to use Google Apps Script.

With it, I'm making a request to my profile page with UrlFetchApp and I'm extracting from the response text the "d+ profile views" text (where d is a digit).

However, it seems that each request triggers a profile view. (Either that or coincidentally someone visited my profile at that time, which I doubt).

I would like to prevent my script to trigger a profile view, perhaps by adding something in the header?

Is it possible?

1
  • 2
    The Stack Exchange API allows you to get all sorts of user data. I haven't played around with it myself so don't know for certain if it will trigger a page view, but it might be worth looking into. Jul 6, 2018 at 13:29

1 Answer 1

7

Making an HTTP call to your profile page triggers the view count to go up, at least once every 15 minutes.

Don't scrape for data that is available in the Stack API. Users-by-id offers you in the user type the view_count which holds your profile view count.

Here is a stack snippet that fetches your profile view count for MSE:

// find the html element and bind the model
function showItem(item) {
   document.getElementById('vc').textContent = item.view_count;
}

var xhr = new XMLHttpRequest();

// what do we fetch
xhr.open(
  'GET',
  'https://api.stackexchange.com/2.2/users/271865?order=desc&sort=reputation&site=meta&filter=!)RwcIFN1K)cI6NxyKTp7GH9R');

// handle success !
xhr.addEventListener('load', function() {
  var data = JSON.parse(xhr.responseText);
  if (data.items && data.items.length > 0) {
    showItem(data.items[0]);
  }
});

// just do it
xhr.send();
<div>
Profile views:&nbsp;<span id='vc'></span>
</div>

Keep in mind you can only make 300 calls per day from one IP. If you need more, register your app for a key.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .