How do I get user activity data from the Google API - google-analytics

I want to retrieve user activity data using the Google Analytics Reporting API. I code in PHP (not that it's relevant to this question)
I am following instructions from here: https://developers.google.com/analytics/devguides/reporting/core/v4/user-reporting
I am using the _ga client ID cookie stored in browser for the "userId", but I get the following response:
{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED", "details": [ { "#type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "CREDENTIALS_MISSING", "domain": "googleapis.com", "metadata": { "service": "analyticsreporting.googleapis.com", "method": "google.analytics.reporting.v4.Reporting.SearchUserActivity" } } ] } }
This seems like I have to let the user sign into Google before I can get the desired data.
Is it possible to get this data from just the _ga cookie ID, without the user signing in?
Below is the request from the client. They say I need to use the Google Reporting API. This also seems like it can only work once signed in?
When a lead is submitted using the contact form, capture the Google Analytics ClientID (stored in the _ga cookie in the browser) as part of the submission.
Using the ClientID, interrogate the Google Analytics Reporting API for the "first interaction" (first session) user activity linked to this lead, fetching the data linked to the following variables:
Source
Medium
Campaign Name
Campaign Content
Campaign Term
Search Query
Once the data has been retrieved from the GA API (which can sometimes take up to 15 minutes to populate in the GA databases), pass the full payload, including the lead details and the marketing characteristics through to the CRM.

Related

How to get customers orders list using their own rest api creds

I have created a new Rest API credentials for a customer.
Now I am using the following api to get the orders for that particular user.
/wp-json/wc/v3/orders
but I get the following error in the response
{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
"status": 403
}
}
I have tried with both basic auth and keys in url parameter, but it's not working. If the rest api belongs to that particular user then it should return the users order but it is giving me error.
Please help
Even I am not able to get the product list with the customer's api credentials.
A few things:
The REST API doesn't belong to a customer, it's just WooCommerce functionality.
You need to create API keys for yourself - the user that will be using the REST API. Not for the customer whose information you need. If THAT customer will be using your site's REST API, he will need his own credentials.
The endpoint you're using will give you all orders. For a specific one, you need to use this endpoint: /wp-json/wc/v3/orders/<id> (replace "<id>" by an order ID).
For orders of a specific customer, you can add a customer parameter (List all orders documentation
In the Postman Authorization tab, choose "Basic Auth", enter the key and secret there, and test it with the "All orders" endpoint. That should work.

google calendar api send as another user on our domain using service account

I have a service account, and I downloaded the credentials that look like:
{
"installed":{
"client_id":"abc123",
...
}
}
And I go through the procedure of running the node.js based code which attempts to create the token file with getNewAccessToken, and it gives me the prompt:
Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth?ac...
When I go to the link, it asks me to log in with my google account.
That sets the token and I can send google calendar events where the calendar id is set to primary (and it is set to be from me) but I can't set the calendar id to John.Smith#mycompany.com
It says
{
"domain": "calendar",
"reason": "requiredAccessLevel",
"message": "You need to have writer access to this calendar."
}
I am not sure how to make it so my service account can be used to send events on behalf of our staff members. Is it because when authorizing I logged in as my account instead of the service account, and if so, how do I authorize as the service account.
Update: I am using the code provided in the google calendar api quickstart guide

Can't reproduce payment instrument token creation action from sandbox with "Invalid profile owner" error

I want to create a token for card with given API call https://developer.cybersource.com/api-reference-assets/index.html#token-management_payment-instrument_create-a-payment-instrument as CyberSource's Intro video suggests. With default credentials that sandbox provide(testrest merchant) everything goes fine but when I use my credentials generated in https://ebc2test.cybersource.com I am always getting next error(I don't edit initial request that sandbox provides; with this exact request and default credentials CyberSource generates token and successfully returns it to API test page)
{
"errors": [
{
"type": "forbidden",
"message": "Invalid profile owner"
}
]
}
I have tried to use merchant API shared key/secret as well as user-specific credentials from the same merchant profile.
What I did wrong(may be I need to change smth in merchant profile) and what I need to do to make it work ?
We had the same problem. It was related to the profileId. The hard coded profile id isn't valid. You need to get your own profile id from customer support. From what I gather the profile id is used to reference your specific tokens. It's a discount double check if you will that the tokens you are inputting are connected to your account.
The profile id within a REST API context is assigned by CyberSource within the Gateway account and with TMS is a specific id for your TOKEN MANAGEMENT collection.

firebase signInWithCustomToken broken

At first, just yesterday everything worked. But from this morning, I got the case.
On back-end (NodeJS) I generate custom token with auth().createCustomToken(SOME_ID)
Then, when I call on client side signInWithCustomToken() with token I got from back-end, I get the next error:
{
code: "auth/invalid-custom-token",
message: "The custom token format is incorrect. Please check the documentation."
}
In logs there's a POST to https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=MY_API_KEY, with params { returnSecureToken: true, token: MY_GENERATED_TOKEN } with status 400 and response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "INVALID_CUSTOM_TOKEN"
}
],
"code": 400,
"message": "INVALID_CUSTOM_TOKEN"
}
}
So, did google introduced some breaking changes or what?
**
Manage User Sessions
**
Firebase Authentication sessions are long lived. Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token (a JWT) and refresh token. Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens. Refresh tokens expire only when one of the following occurs:
The user is deleted
The user is disabled
A major account change is detected for the user. This includes events like password or email address updates.
The Firebase Admin SDK provides the ability to revoke refresh tokens for a specified user. In addition, an API to check for ID token revocation is also made available. With these capabilities, you have more control over user sessions. The SDK provides the ability to add restrictions to prevent sessions from being used in suspicious circumstances, as well as a mechanism for recovery from potential token theft.
https://firebase.google.com/docs/auth/admin/manage-sessions
On the client side such as Angular. If you use the AngularFire2 you can use a command called signInWithCustomToken(clientToken) and pass the customToken. This will provide you with an acceptance to sign in or a rejection.
If firebase rejects, then take the rejection and either redirect the user to a login page using routes or just provide a way to login. Your call.
Just remember to let Firebase handle the decoding of the JWT. Provides better security if you do not show decoding on your side.
I had the same problem. The reason was that the token was expired.
The Firebase SDK throws the same error: auth/invalid-custom-token error for both malformatted tokens and expired tokens.
Hopefully, the error handling improves soon, in the meantime developer can check to see if a token is expired by using a client side library like jtw decode and checking the "exp" timestamp and comparing to the current time.
timeSeconds=TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
expSeconds = timeSeconds + 60L * 60L;
and set claims to this values
.claim("iat", timeSeconds)
.claim("exp", expSeconds)
the result from verification:
"kind": "identitytoolkit#VerifyCustomTokenResponse",
"idToken": "",
"expiresIn": "3600",
"isNewUser": true
stackoverflow.com/questions/45110441/firebase-auth-invalid-custom-token

Search Person Information by there email id using Graph API Facebook

I want to Search the person basic information like email,name,address etc by passing there email id on graph API of facebook. But its not working and its returning me the message
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
I am passing url like below-
https://graph.facebook.com/search?q=EMAIL_ID&type=user&access_token=ACCESS_TOKEN
Please suggest me how can I able to search information by passing email id in graph api. and also if I logged out and then logged in back then my this access_token is not working. Do I need to get different access token each time? Please suggest.
Thanks

Resources