{"id":1020,"date":"2015-08-28T02:41:01","date_gmt":"2015-08-27T20:41:01","guid":{"rendered":"http:\/\/promincproductions.com\/blog\/?p=1020"},"modified":"2017-04-05T19:13:35","modified_gmt":"2017-04-05T13:13:35","slug":"google-api-access-google-search-analytics-from-google-search-console","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/google-api-access-google-search-analytics-from-google-search-console\/","title":{"rendered":"Google API &#8211; Access Google Search Analytics from Google Search Console"},"content":{"rendered":"<p>In early August Google announced that they have <a href=\"http:\/\/googlewebmastercentral.blogspot.com\/2015\/08\/introducing-search-analytics-api.html\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"474\">released an API to the Google Search Analytics<\/a> data from Google Search Console (formerly Google Webmaster Tools).<\/p>\n<p>I started building upon this API and was able to import data into a MySQL database. \u00a0All was going well, and then I ran into my first snag in that my computer died. \u00a0It took me a few weeks to be able to at least recover the code from the localhost dev site I was building this at.<\/p>\n<p>So fast forward a few weeks and I have the code back and a computer to develop it on. \u00a0All is going fine, my import to MySQL from Google Search Console (Google Webmaster Tools) is working great for the one website I was testing this with. \u00a0Then I start to explore adding more websites, and nothing but errors. \u00a0I confirm that I&#8217;m making a successful OAuth2.0 connection to Google, etc. \u00a0Insert too much time spent in frustration, analyzing code, debugging, etc.<\/p>\n<p>Bottom line was this &#8211; though you have granted access to the API via OAuth2.0, you still need to grant access to your user in Google Search Console for each website you are attempting to access.<\/p>\n<h2>Grant Access to Google Search Console from a Google Developers Console API User<\/h2>\n<p>Let me expand on that just a bit because this was all kind of confusing to me.<\/p>\n<p>In the <a href=\"https:\/\/console.developers.google.com\" target=\"_blank\" rel=\"nofollow noopener\" data-lasso-id=\"475\">Google Developers Console<\/a>, you first need to create a project if you haven&#8217;t done so already.<\/p>\n<p>Next, you need to add access to the <strong>Google Search Console API<\/strong>. \u00a0This is done within the Google Developers Console while your project is active.<\/p>\n<ul>\n<li>Choose\u00a0<strong>APIs &amp; auth<\/strong> -&gt;\u00a0<strong>APIs<\/strong><\/li>\n<li>In the search field, search for\u00a0<strong>Google Search Console API<\/strong><\/li>\n<li>Choose this API from the list.<\/li>\n<li>Click the\u00a0<strong>Enable API<\/strong> button.<\/li>\n<\/ul>\n<p>Then also within the project, configure two sets of credentials &#8211; an OAuth2.0 client ID and a Service account.<\/p>\n<ul>\n<li>OAuth2.0 client ID\n<ul>\n<li>As I understand it, this is the basic authentication level that I believe is required to get your API calls access. \u00a0Typically, this level of access should prompt an authorization screen that the user would click a button to grant access. \u00a0In my case, I want the authentication built into a configuration script and thus I need to add a Service account as well.<\/li>\n<\/ul>\n<\/li>\n<li>Service accounts\n<ul>\n<li>These allow you to authenticate the user in the code base and thus skip the authentication screen when the application needs to grant access. \u00a0This requires programming in your authentication information.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<figure id=\"attachment_1021\" aria-describedby=\"caption-attachment-1021\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials.jpg\" rel=\"attachment wp-att-02\" data-lasso-id=\"476\" data-rel=\"lightbox-gallery-f6kxLbk1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" class=\"size-medium wp-image-1021\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials-500x179.jpg\" alt=\"google api google search analytics credentials\" width=\"500\" height=\"179\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials-500x179.jpg 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials-768x275.jpg 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials-150x54.jpg 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials-600x215.jpg 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-api-google-search-analytics-credentials.jpg 970w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-1021\" class=\"wp-caption-text\">Create an OAuth2.0 client ID and a Service account within the Google Developers Console<\/figcaption><\/figure>\n<p>Now that you have your authentication credentials setup, you need to grant access to this API &#8220;user&#8221; within Google Search Console (Google Webmaster Tools). \u00a0To do this, you&#8217;ll need to copy the <strong>email address<\/strong>\u00a0displayed for the <strong>Service account<\/strong>. \u00a0Then head over to <a href=\"https:\/\/www.google.com\/webmasters\" target=\"_blank\" data-lasso-id=\"477\" rel=\"noopener\">Google Search Console<\/a>.<\/p>\n<ul>\n<li>Log into Google search console<\/li>\n<li>From the right hand side of the screen for a website, choose\u00a0<strong>Manage property<\/strong> -&gt; <strong>Add or remove users<\/strong><\/li>\n<li>Choose\u00a0<strong>ADD A NEW USER<\/strong><\/li>\n<li>Enter the email address you copied above from Google Developers Console in the\u00a0<strong>User email<\/strong> field.<\/li>\n<li>Set the\u00a0<strong>Permissions<\/strong> drop-down to\u00a0<strong>FULL<\/strong><\/li>\n<li>Click the\u00a0<strong>ADD<\/strong> button<\/li>\n<\/ul>\n<figure id=\"attachment_1022\" aria-describedby=\"caption-attachment-1022\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access.jpg\" rel=\"attachment wp-att-022\" data-lasso-id=\"478\" data-rel=\"lightbox-gallery-f6kxLbk1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" class=\"size-medium wp-image-1022\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-500x227.jpg\" alt=\"google search console grant user access\" width=\"500\" height=\"227\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-500x227.jpg 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-768x348.jpg 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-1024x464.jpg 1024w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-150x68.jpg 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access-600x272.jpg 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access.jpg 1125w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-1022\" class=\"wp-caption-text\">Grant access to Google Search Console data for a Google Developers Console user via API access and OAuth2.0 authentication.<\/figcaption><\/figure>\n<p>This now grants\u00a0the Google Developers Console API user\u00a0access to the Google Search Console website property, and thus it&#8217;s data as well.<\/p>\n<p>This should be everything you need to have your program talk to Google Search Console (Google Webmaster Tools) via API authenticated via OAuth2.0<\/p>\n<h2>Google Search Console API &#8211; PHP<\/h2>\n<p>I&#8217;m a PHP developer for the back end, so that&#8217;s my language of choice. \u00a0But there are other languages that can access the API &#8211; but that&#8217;s out of scope of this article.<\/p>\n<p>I&#8217;m not going to go into detail on how to program access to the API in this post. \u00a0But <a href=\"https:\/\/developers.google.com\/api-client-library\/php\/\" target=\"_blank\" data-lasso-id=\"479\" rel=\"noopener\">Google does offer a PHP library for accessing their APIs<\/a>. \u00a0Feel free to explore an use that as you wish.<\/p>\n<h2>Import Google Search Analytics Data from Google Search Console to MySQL<\/h2>\n<p>Again, there are many ways to accomplish the task of importing your search analytics data from Google to a locally hosted location, but I&#8217;m not going to go into full detail on how to accomplish that.<\/p>\n<p>What I will do however, is share with you a github repository that offers a set of instructions and a tool to copy your data from Google Search Console to your own MySQL database.<\/p>\n<p><a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\" target=\"_blank\" data-lasso-id=\"480\" rel=\"noopener\">Import Google Search Console data to a locally hosted MySQL Database<\/a><\/p>\n<p>I should note &#8211; I&#8217;m the developer of that github repository and would love input and\/or feedback on the project. \u00a0At the time of writing this it is in it&#8217;s infancy, but I intend to develop this into a more full suite of tools in the future.<\/p>\n<h2>Help \/ Troubleshooting<\/h2>\n<p>If you install and run the <strong>Organic Search Analytics tool<\/strong> to manage your own data and run into issues or something that just isn&#8217;t quite right, please look to the <a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\" target=\"_blank\" data-lasso-id=\"481\" rel=\"noopener\">official github page<\/a> for this project. \u00a0Feel free to reach out for help as well if needed, posting any error messages or strange situations you may find on the github repository by <a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\/issues\" target=\"_blank\" data-lasso-id=\"482\" rel=\"noopener\">creating an issues<\/a>. \u00a0This is where the codebase lives, gets updated, and I as the developer as well as other users can help you find a resolution to any issues you may come across.<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\/issues\" target=\"_blank\" data-lasso-id=\"483\" rel=\"noopener\">Issues<\/a>\n<ul>\n<li>Search old issues to see if someone else has encountered the same issue as you<\/li>\n<li>Report an issue or bug<\/li>\n<li>Request new features<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\/pulls\" target=\"_blank\" data-lasso-id=\"484\" rel=\"noopener\">Pull Requests<\/a>\n<ul>\n<li>Offer suggestions for code changes<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\/wiki\" target=\"_blank\" data-lasso-id=\"485\" rel=\"noopener\">Wiki<\/a>\n<ul>\n<li>The &#8220;Owners Manual&#8221; for Organic Search Analytics<\/li>\n<li><a href=\"https:\/\/github.com\/PromInc\/organic-search-analytics\/wiki\/Roadmap\" target=\"_blank\" data-lasso-id=\"486\" rel=\"noopener\">Roadmap<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>In early August Google announced that they have released an API to the Google Search Analytics data from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1022,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[50,13,49,5],"tags":[],"class_list":["post-1020","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","category-php-development","category-seo","category-website-development"],"jetpack_featured_media_url":"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2015\/08\/google-search-console-grant-user-access.jpg","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-gs","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=1020"}],"version-history":[{"count":3,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1020\/revisions"}],"predecessor-version":[{"id":1482,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1020\/revisions\/1482"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media\/1022"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=1020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=1020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}