I discovers the use of GA report API. Yours helps and precisions are very important for me. I want to get datas from GA report api with a json format.
I have making a test : I have installed the GA client with composer, create an app, a service account credential, and create the HelloAnalytics.php script. It's ok I get datas with this script.
But, I want to retrieve datas with a json format. Then, I think that this method is not good. I think that I must use a query to get datas from GA api. Isn't it?
If yes, how can I associate the service account credential with a query to GA api? By default, a query to GA api has need 1 token.
Can you explain me how to proceed? Thanks very much for your help.
You mentioned composer which leades me to beleave that you are using php. If you are using the PHP client library then it returns all the data to you as objects.
Google APIs by default return their data as Json but the client libraries to make it easier for you return it as an object.
You might try the json_encode($b) method which should if memory serves take an object and turn it into json for you.
Related
I have a Google Cloud Function. I also have a web application. I want to authenticate requests to the cloud function by using a service account.
I have the json key file.
I know that I have to follow https://cloud.google.com/functions/docs/securing/authenticating#service-to-function. But that is leading me to an IAP page that does not apply to google cloud functions.
Another similar instructions are found in https://developers.google.com/identity/protocols/oauth2/service-account
But if I am following the python library code, I end up with the sample code there :
import googleapiclient.discovery
sqladmin = googleapiclient.discovery.build('sqladmin', 'v1beta3', credentials=credentials)
response = sqladmin.instances().list(project='exciting-example-123').execute()
This does not directly relate to invoking a cloud function.
This question's answer somewhat deals with my requirement but is using a Call API which is only suitable for testing.
Also, I want to expose this API to multiple applications using another tech like .net. So I believe the best option for me will be to use the HTTP method (given on the same page):
https://developers.google.com/identity/protocols/oauth2/service-account#httprest
But whatever I do I am unable to get the signature right.
Any help to get this sorted will be highly appreciated as I am stuck on this for the past few days.
You can use the Google auth library like this
from google.oauth2.id_token import fetch_id_token
from google.auth.transport import requests
audience="my_audience"
r = requests.Request()
token=fetch_id_token(r,audience)
print(token)
The fetch_id_token method will use the default credentials
The service account key file defined in the environment variable GOOGLE_APPLICATION_CREDENTIALS
The service account loaded in the Google Cloud environment
For now, I followed this answer in PHP
In the claims section, I removed the scope. Instead added a claim of target_audience.
"target_audience" => "google-function-http-trigger"
the cloud function http trigger will look like https://us-central1-test-project-name.cloudfunctions.net/function-name",
This will give the required assertion key.
Then I follow https://developers.google.com/identity/protocols/oauth2/service-account#httprest to get the id_token
Then with the id_token as the bearer token we can call the cloud function.
please note that the token expires depending on the time set in the "exp" claim. Once expired you have to redo the steps to generate the new id_token
I want to authenticate requests to the cloud function by using a service account.
I am not sure I understand the context correctly, but I would try to assign a roles/cloudfunctions.invoker IAM role to that service account (which is used to run your code in the web application) - see Cloud Functions IAM Roles .
In that case a code under that service account "Can invoke an HTTP function using its public URL"
I reckon no json keys are required in this case.
I need to provide every user with data from different sites. Each of the site provides data in JSON format, but some of them have restriction to maximal number of request.
My idea for solution is to download the data to firebase periodically, than users will access just the firebase database.
From docs it seems to me that firebase can somehow use http requests.
Can I use firebase to periodically update itself by http request?
Or should I establish server which will do the task?
I am pretty new to those topics so any tip where to look for information will be appreciated.
I'm currently creating a chrome extension that will query EnvironmentHubMember records from our Salesforce org, however I'm currently getting this returned from the REST callout;
'"sObject type 'EnvironmentHubMember' is not supported."'
The endpoint I'm using is 'INSTANCENAME.COM/services/data/v20.0/query/?q=SELECT+Name+FROM+EnvironmentHubMember
I can't seem to find any specific settings to make this sObject available via an api call, has anybody been able to query these records from an external system before?
Thanks!
try using a later API version. The object itself was not available in version 20. The most recent version is 41.
Im trying to validate if the contacts that I have imported to the outlook contacts is been important, I was thinking to use and API call to get an JSON file to see if the contacts have been imported correctly or not.
I am fairly new to using API calls and Im not sure how to use Microsofts outlook APIs to achieve my goal.
any snippet code in Java, C#, Node.js would help
Im also not sure how I can get the auth key
Thanks in advance
First you need to decide what kind of authentication approach you need to use, and then you need to register your application. This article can help you decide: https://developer.microsoft.com/en-us/graph/docs/authorization/auth_overview.
Once you have acquired a token, use the Contacts REST API to work with contacts data. There are examples here:
https://msdn.microsoft.com/office/office365/APi/contacts-rest-operations
You can also use the Graph Explorer to test out various API calls and see the results in JSON: https://developer.microsoft.com/en-us/graph/graph-explorer
I'm trying to figure out how to insert/update data into offsite databases that don't have an API available. Since they don't have an API, I thought of an approach I can take to insert/update data into their database.
They would first need to build a script and place it in an accessible location on their webserver that I can access via a URL. They would be required to supply the URL to me. I then can do a cURL POST request to that URL and pass a JSON array of the data that needs to be inserted. The script on their server would handle the parsing of the JSON array and the insert/update into the database.
I think this should work, but what security issues would I be opening them up to?
What you described is them creating an API. Just because the url invokes a script and isn't written in something like Java or PhP doesn't mean its not an api.
You need to make sure your url is secure so only authorized people can invoke it, and they would probably want to do data validation.
You should let them decide whether that is easier than standing up a more robust/non-script based solution