chrisle / seer.js

An all-in-one toolbox made for SEOs
200 stars 50 forks source link

Google Analytics API calls fails authentication #2

Open chrisle opened 10 years ago

chrisle commented 10 years ago

But I got this report twice via email and tried it myself just now. Definitely an issue. It's possibly due to an external change in the API but I don't know yet.

I'm doing this outside my 9 to 5, so any help would be appreciated!

baz commented 10 years ago

I use 2-factor auth so I generated a new one-off app password.

The end-result for this should be the same as if I had entered in my Google username and password.

I then copied and pasted https://github.com/chrisle/seer.js/blob/master/build/seer.js into the Script Editor and saved it.

I wanted to get a GA function executing and returning results so I found getGaKeywordCount() which had the smallest number of arguments and tried to call it.

In A2 of Sheet1 I entered the following: =getGaKeywordCount(1,A4,A5)

I couldn't figure out how to enter date objects into Google Docs so I modified the source code instead.

Here's what I replaced getGaKeywordCount() with:

function getGaKeywordCount(profileId, startDate, endDate) { 
  var sd = new Date(2013,10,2);
  var ed = new Date(2013,11,2);

  return (SeerJs.Error.hasOccurred()) 
      ? SeerJs.Error.get() 
      : SeerJs.GaApi.keywordCount(1, sd, ed); 
}

After that, A2 started returning me figures. And whenever I adjusted the date ranges inside of getGaKeywordCount() I'd get different values.

And that was the extent of my explorations into SEO Toolbox.