Use Google SearchConsoleR Data in Shiny Application - r

I have created an API Key, OAuth 2.0 Client IDs json file, and a service accounts email. How can I automatically connect without opening up the browser for authentication to the google search console with the searchConsoleR package?
For googleAnalyticsR I did this
googleAuthR::gar_set_client(json = here::here("credentials/client_id.json"))
googleAnalyticsR::ga_auth(email = "email",
json_file = here::here("credentials/file.json"))
But I am unable to connect to the search console. Is there any good documentation how I can connect to google search console in an automatic way without authentication in the browser?

Take a look at this:
options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/webmasters")
gar_auth_service(json_file = "/service-account-key.json")

Related

Accessing Google Sheet to Create a sheet(GCP)

I want to Fetch data from firestore and append all the data in a new Google sheet.
Creating sheet is where i am finding problem.
as far as i have researched, i ve found out there are 3 methods to access google api,
1)API key
2)Service account
3)Oauth
Ignoring API key,
While using service account, i have found out that sheet which is getting created will be owned by service account so no one else can remove it.
when using Oauth, i have used OAuth json credential from GCP , in which when i try to use it in local host, it shows me Google's Logging screen, but when i deploy it in app engine, it doesnt redirect it to logging screen.
https://developers.google.com/sheets/api/quickstart/nodejs
this is the document where i find the approach.
One more method i have found i.e. Access token. i.e. putting access token in
const sheets = google.sheets({ version: "v4",headers:{ Authorization:`Bearer ${accessToken}` }});
but that wont be possible, as in Front end i am using
auth.onAuthStateChanged
which doesnt provide me Access token just the ID token.
Please help!
Based on your auth.onAuthStateChanged code it looks like you're using Firebase Authentication to sign in on the frontend.
Firebase Authentication is based around JWT ID tokens, which are not the same as OAuth tokens. You can't use such an ID token to make calls to the Google Sheets API.
If you're signing in with Google or another OAuth provider on the frontend, you can capture the OAuth token from that provider before you sign in to Firebase with it, and then use the OAuth token to call the Google Sheets API.

firebase firestore gives error for a project that's been added to firebase projects

I've added my project to firestore and I'm doing firestore google auth just fine.
My problem is firebase firestore.
It just doesn't work and I have no idea why.
I'm trying to do a simple add before doing the actual process for my app and it doesn't work.
here I implemented a simple function to add a user and then called it, doing it all in build function.
I get this in my console:
p.s.
"adding user" is printed on console.
p.s.
I do have the firebase_options.dart file.
These thing are you sure that the correct:
1.Using correct google_services.json file
2.Edit Fire store rules if you are not using authorization
You have to manually whitelist your existing Google OAuth 2.0 client IDs in the Firebase console before using it with the new Auth APIs.
In order to do so, follow these steps:
Go to the Credentials section in the Google API Console.
Select from the top right corner the project where you had previously configured Google Sign-In.
Go to the OAuth 2.0 client IDs section
If you are using Google Sign-In on Android or iOS applications:
Take note of the Client ID string corresponding to all the entries registered for your applications.
Input these Client IDs into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add there all you client IDs, to the whitelist of client IDs from external projects.
If you are using Google Sign-In on a web application:
Click to open your web client ID and take note of both the client ID and secret.
Input this Client ID into your Firebase project’s configuration:
Go to the Firebase console at https://console.firebase.google.com
Open the Auth section
Under Sign-In methods, open the Google configuration, and add the values under the Web SDK configuration section.

How do I connect my Firebase database to a Google script?

I am trying to put pictures that are on Firebase into a google Drive by using google App script. I've no code, I only tried reading the documentation, but it seems to be deprecated. There seems to be a way to use an Oauth token but I could not find a token on my firebase database.
I go into a lot of detail about using OAuth2 and service accounts with Google Apps Script in this story on Medium.
I suppose you want to use Firebase storage? The approach should be similar:
Create a service account
Use the OAuth2 library to generate a Bearer token
Use that token with the API call via UrlFetchApp
It would help if you shared more details on what you're trying to achieve, but this should set you on the right track.

firebase Cloud Json API using API KEY

I am trying to explore Cloud Storage JSON API V1, as mentioned in request, the GET request can be called with a key, I have tried many keys, I have created in credentials panel, but I am only getting keyInvalid or any other error, I want to know about this key, which API key Google Cloud Storage is using here
GET https://www.googleapis.com/storage/v1/b/wearableeot-39e6a.appspot.com?key={YOUR_API_KEY}
Thanks for help, I only want to know about this API Key.
I think you should follow the instructions you find here: https://cloud.google.com/storage/docs/json_api/v1/how-tos/authorizing#APIKey
In a nutshell, you should:
Go to the Credentials page in the Google Cloud Platform Console (not the Firebase console), for your project.
Click the "Create Credentials" drop-down box and choose "API key": you get the key in a dialog box.
Possibly restrict the key. See more infos here

R script to import data from google analytics

I am trying to connect to google analytic s API through a script running on R studio server.
I have followed steps from this tutorial:
http://www.r-bloggers.com/how-to-extract-google-analytics-data-in-r-using-rgoogleanalytics/
If I run this on localhost, it works alright but when I try to run the script on a remote server through R studio,
authroization step does not complete because it tries to connect to the url on localhost i.e
localhost:1410/
instead of REMOTESERVERHOSTNAME:1410
I found this post which suggests port forwarding if running through R studio : link
but if tomorrow, if I want to access it on the other host computer, I would not want to set port forwarding first.
How to run this script without having to set port forwarding?What are other ways for oauth authentication for my R script?
One suggestion would be to use a Google Service Account. The googleAuthR package by Mark Edmondson, available through CRAN, provides functionality to perform server-side authentication in R using a Google Service Account. Another package by the same author called googleAnalyticsR, also on CRAN, integrates with googleAuthR and uses the resulting authentication token to execute queries against the Google Analytics Reporting APIs, including the latest version, 4.0.
To achieve this:
Create a service account for your Google API project.
Download the JSON file containing the private key of the service account.
Grant the service account access to Google Analytics, in the same way as you would for any other user.
Supply the location of the private key JSON file as an argument when authenticating with googleAuthR (see the example below.):
The following example R script references the JSON file containing the private key and performs a basic Google Analytics reporting query. Remember to set the json_file argument to the appropriate file path and the id argument to the appropriate Google Analytics view:
library(googleAuthR)
library(googleAnalyticsR)
gar_auth_service(
json_file = "API Project-xxxxxxxxxxxx.json",
scope = "https://www.googleapis.com/auth/analytics"
)
google_analytics(id = "123456789", start = "2016-06-01", end = "2016-06-28")

Resources