Forum Discussion

lindajzmin's avatar
lindajzmin
Frequent Visitor
2 years ago

Error connecting to Google Search Console API in Power BI using R script

 

Hi everyone,

I am trying to connect to the Google Search Console API using an R script in Power BI. I have successfully done this before with the Google Ads API and the Google Analytics 4 API, so I have the necessary Google permissions and authentication.

This time, I have added the permissions in the Google Search Console domain, but I am getting the following error, which I find strange because the code works perfectly in R. Does anyone know if I need any special permissions in Power BI?

 

Details

  • Error message:

ADO.NET: Script R error. Fetching search analytics for url: https://wwwxxxxxxxxxx/ dates: 2023-01-01 2023-01-31 dimensions: country dimensionFilterExp: searchType: web aggregationType: auto 2024-02-14 13:33:54.523797 > Request Status Code: 403 Error in `abort_http()`: ! http_403 Request had insufficient authentication scopes. Backtrace: 1. searchConsoleR::search_analytics(...) 2. googleAuthR (local) search_analytics_g(...) 3. googleAuthR:::doHttrRequest(...) 4. googleAuthR:::retryRequest(...) 5. googleAuthR:::abort_http(status_code, error) 6. rlang::abort(...) Execution interrupted

 

 

Additional information:

  • I have already successfully connected to the Google Ads API and Google Analytics 4 API using R scripts in Power BI.
  • I have added the necessary permissions for the Google Search Console API in the Google Cloud Platform Console.
  • The R script works perfectly when I run it in RStudio.

Any help or suggestions would be greatly appreciated.

Thanks in advance,

Linda

P.S. I have also attached the R script for your reference.

R script:

 

library(searchConsoleR)
library(googleAuthR)

 

options(googleAuthR.scopes = c("https://www.googleapis.com/auth/webmasters"))

gar_auth_service("C:/Users/linda/OneDrive/Documentos/xxxxxx.json")

 

gsc <-
search_analytics(siteURL = "https://www.xxxxxxxx.xx/",
startDate = "2023-01-01",
endDate = "2023-01-31",
dimensions = "country",
searchType = "web",
rowLimit = 5000)

3 Replies

  • Hi lindajzmin were you able to find a solution? As a workaround, maybe you can try to test your connection with a 3rd party connector. I currently use windsor.ai 's Search console connector and I haven't had any problem with my data. In case you wonder, to make the connection first search for the GSC connector in the data sources list:

     

     

    After that, just grant access to your GSC account using your credentials, then on preview and destination page you will see a preview of your GSC fields:

     

     

    There just select the fields you need. Finally, just select PBI as your data destination and finally just copy and paste the url on PBI --> Get Data --> Web --> Paste the url.

     

    • lindajzmin's avatar
      lindajzmin
      Frequent Visitor

      Thank you very much for your help, but first I will try with R because it is free, and then if it doesn't work, I will switch to windsor.ai... But your suggestion is very valuable.