How can we get the Suspension time of an account using Admin Directory API - google-admin-sdk

I'm trying to get the reports for all the Suspended accounts with a field "SuspensionTime" like the "creationTime". I'm unable to fetch the "SuspensionTime" of an account though the API.
I'm using the following Documentation referred by the Google.
https://developers.google.com/admin-sdk/reports/v1/guides/manage-audit-admin

You can use the activities.list method from the Reports API. The thing with this is that it requires the userKey parameter, which means that you depend on knowing which admin performed the action. It is easier if you have only a couple of admin accounts doing user suspensions.
You would need to send "SUSPEND_USER" in the event name field, and "admin" in the applicationName field to get all the user suspensions performed by that admin, and you will get the date and time in the "time" file of the response.

Apart from the Activities API: https://developers.google.com/admin-sdk/reports/reference/rest/v1/activities/list?apix_params=%7B%22userKey%22%3A%22all%22%2C%22applicationName%22%3A%22admin%22%2C%22eventName%22%3A%22SUSPEND_USER%22%7D
If the suspension comes from Google you can inspect the Users Usage Reports: https://developers.google.com/admin-sdk/reports/v1/appendix/usage/user/accounts
The field disabled_reason usually contains the date of the suspension.

Related

How to differentiate Basic/Premium plan users for premium-only features in Django REST?

I am working on a beta-stage writing tool SaaS that is built with NextJS, React, and Django REST. As I’m gaining some user base, I am starting to research on introducing a premium plan to the mix using Stripe.
As most other SaaSs, I will have a subscription-based premium plan which grants access to premium-only features. However, even after days of research, I am still lost how this is commonly implemented in Django/Backend. Here is what I’ve thought of so far, but again, I am not sure if it’s the best/common way to accomplish this.
User model has a ‘premium’ field which is either True or False
Whenever user clicks on a premium-only API call, Django will check if user is premium or not to decide whether to make the actual API call. I currently have a '/user/me/' route which returns basic user information as API GET call.
Upon successful stripe payment, stripe redirects user to the success_url. Then, somehow I will detect when user lands on success_url and then set that user’s premium field to True.
I know this is not the ideal way, because I already see lots of issues/hurdles:
How will I set ‘premium’ field back to False after user’s payment stops
How can I ‘detect’ stripe’s payment to set user’s premium field
Is this feature supposed to be implemented with Stripe customer objects instead? I would appreciate any guidance on where I should be looking for solutions.
If you use subscription on Checkout Session (low code solution), you can add additional key-value pair data such as premium: true in metadata and subscription_data.metadata fields when creating a subscription.
Once the payment is completed, those metadata will appear in checkout.session.completed and customer.subscription.updated webhook events, which you can then set the user as premium in your own database.
A customer object in Stripe can have multiple subscriptions, so this feature will be implemented on subscription object instead.

Sitecore 9.3 Experience Analytics - tracking logged users and users roles

Can anyone provide me with working example how to show analytics (Visits, Page views, Page views per visit, etc) for logged users? As I understand there is no OOB solution, so I've tried to implement flexible dimensions, but didn't find any good examples and failed.
First of all you have to identify your logged in contact by calling the Sitecore.Analytics.Tracker.Current.Session.IdentifyAs() method, see more details here. When the contact logs in you can use their username to identify them upon the successful login.
Note, that the identification and authentication are separate unrelated events. Contacts are identified against the xDB and authenticated against the authentication mechanism used by the website.
When the contact identifies, it is saved to xConnect with a known identifier based on the information passed into theIdentifyAs() method: Identifier, Source and
IdentifierType will be set to ContactIdentifierType.Known (it is set to ContactIdentifierType.Anonymous for anonymous contacts). Then you can use IsKnown property on the Sitecore.XConnect.Contact that returns true if a contact has any known identifiers.
If you want to track some custom events for the logged in users to then use them for reporting needs you can add user interactions by calling the client.AddInteraction() extension method. I have given an example here.
If you want to extend the contact with your own custom data then you can create custom contact facets, read more here.
In order to implement your custom report with flexible filtering by logged in and not users, of course, you will need to define your custom dimensions and metrics, read more here.

Reports API to retrieve Admin Privilede Granting

I am currently trying to retrieve user events that grant admin or delegate privileges to accounts under our domain. I guessed such event names called GRANT_ADMIN_PRIVILEGE and GRANT_DELEGATED_ADMIN_PRIVILEGES is the one:
https://developers.google.com/admin-sdk/reports/v1/reference/activity-ref-appendix-a/admin-user-events?authuser=1
So, I filled the form in https://developers.google.com/admin-sdk/reports/v1/guides/manage-audit-admin?authuser=1#get_account_events to generate a request like GET https://www.googleapis.com/admin/reports/v1/activity/users/all/applications/admin&eventName=GRANT_ADMIN_PRIVILEGE or GRANT_DELEGATED_ADMIN_PRIVILEGES.
The result is 200 OK, but without any data in it (Of course, I actually granted Privilege to my coworker in last 2 months).
So, is it right to think GRANT_ADMIN_PRIVILEGE or GRANT_DELEGATED_ADMIN_PRIVILEGES is the event name I am looking for to audit granting activities? Or is there something I am missing?
You may want to visit Reports API: Admin Activity – Delegated Admin Event Names which details the admin activity report DELEGATED_ADMIN_SETTINGS type's eventName parameters and properties. For more information, see also the Activities: list method.

Facebook opengraph insights api on specific post id from my app

I want to build a dashboard that returns more customized insights from the insights generated by app.
The app is a facebook connect website that users visit and view a list of products. They can post to facebook about that particular product by sharing a custom story that incorporates that product on their timeline.
When I go to the insights for my app, it does a great job of showing me all social impressions for all custom stories that were generated on my site.
I'd like to narrow that down even more for specific products.
My plan is to record the object ids that are generated by these actions and link them to a partucular product in my database.
I'd then like to create a new dashboard page that will allow me to login, request read_insights permission from me and then use that object_id:product mapping from my database to show how many social impressions where recorded for a given product's object_ids.
Is this possible? I've read alot about it but still haven't found the most elegant way to get a segmented report of social impressions per type of content that was posted.
Thanks for your time.
The implementation all depends on which platform you want your app to run on.
The first major component is you must have a Facebook developers account which is easy to signup for. Just go to developers.facebook.com and register. Takes like 2 mins. After that you will need to create your first app and add the correct domain name where your app will be hosted and what platform it will run on. (iOS, Android, Web, ect.) Once that is finished you can make your app public so you can use the Facebook API in your code.
For the app creation itself. The first thing you need to do is import the correct API for your platform. Which you can find a walk through at https://developers.facebook.com/docs/. Once the API is imported you must build a Facebook object which contains your app id and possibly app secret. If you're using JavaScript you don't want to use the app secret because it will be visible to the public.
Now that you have your Facebook object you must require the app users to log in and grant permission to your app. You can add extended permissions to your log in process by adding a scope value to the log in button generated by Facebook. Here is an example.
<fb:login-button id="loginBtn" max_rows="1" scope="basic_info,read_insights,manage_pages" size="medium" show_faces="false" auto_logout_link="true"></fb:login-button>
After the user is logged in you can now query information from the users account using Facebook Api calls to Social Graph. Facebook also provides a tool to help you figure out what information you can query. https://developers.facebook.com/tools/explorer
Everything else you want to do with the app can be done by Facebook API calls. You just need to insure you grant the user the correct permissions before making the API calls.
API calls are a little different depending on which language syntax you are using but they all follow the same data model and return some array of responses which can be parsed using JSON or the standard array format. The Graph Explorer tool listed above will show you the output for your queries so you can handle them accordingly.
I hope this helps gets you started.
EDITED
Here's the implementation in JavaScript
function getMetric(){
// make the API call
FB.api(
"/{app-id}/insights/application_opengraph_story_impressions",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
}
Here's the reference now that Facebook docs are back up https://developers.facebook.com/docs/graph-api/reference/insights
application_opengraph_story_impressions will probably give you the total impression of all stories made by your app. I ran it against my Facebook app and it came back empty but I don't have any stories so it might work with your's. Also to note in the documentation there is an * by this metric and I could't find what that means.
I'm pretty sure that right now Facebook don't give developers ability to get insights about app custom stories.
Currently Facebook documentation has the following Graph APIs for Insights data:
/{page-id}/insights
/{app-id}/insights
/{domain-id}/insights
/{post-id}/insights (where this is a Page post)
So /{post-id}/insights won't work because custom story is actually user's post and others endpoints don't apply to your case.
As far as I know the only other option to access Insights is FQL. For that you'd use insights table in a manner similar to this:
SELECT ... FROM insights WHERE object_id = ... AND metric = ... AND end_time = ... AND period = ...
Now most likely this also won't work with your custom story posts (I don't have posts which I could try it on right now, so I can't tell) but at least it is not explicitly stated so in the documentation, so you should probably try it out.
UPDATE:
I wasn't able to get any insights data via FQL, although as far as I understand the following code should have gave me at least something (object id is for my page):
SELECT breakdown, end_time, event, metric, object_id, period, value FROM insights WHERE object_id = 224981264214413 and metric = 'page_fans' and period = period('lifetime') and end_time = 1395597892
But it results just in
{
"data": []
}
Facebook also has some pretty old bug report about similar topic: https://developers.facebook.com/x/bugs/508088155954330/ where they confirmed the issue, assigned it, and... did nothing to fix it for 6 months.
In case FQL doesn't work, my suggestion to you is - use your own analytics code to track the creation of custom stories and get the friend count of the users. It won't show you the real exposure of the posts but at least you will see some data on which types of custom stories where posted more often and what was the maximum potential friend count that could have seen them. By the way - to make charting easier, you could use Google Analytics events for that.

Hierarchical RESTful URL design

I have perused the questions asked about this, but I still don't have a definitive answer.
I have an application and would like to build a RESTful API to expose a subset of information. I have three resources:
users
reports
photos
Users have reports and reports have photos. Photos cannot exist outside of reports and reports cannot exist outside of users.
I have designed the following URLs for my requirements
User login, server responds with token which is sent in the header of all API calls
GET example.com/api/
Get user info
GET example.com/api/users/{username}
Get all user reports
GET example.com/api/users/{username}/reports
Get all photos of a report
GET example.com/api/users/{username}/reports/{report_id}/photos
Add a photo
POST example.com/api/users/{username}/reports/{report_id}/photos
Delete a photo
DELETE example.com/api/users/{username}/reports/{report_id}/photos/{photo_id}
Modify photo description
PUT example.com/api/users/{username}/reports/{report_id}/photos/{photo_id}
Questions
Is it good practice to add a resource id in the URL, i.e. resource/id, or should this rather be added as a query parameter?
Is this method of chaining resources, i.e. resource/id/sub-resource/id/etc., acceptable and good or should I put all my resources at the top level and specify its position with query parameters?
Nothing wrong in this design.But this creates long URL which sometime are difficult to understand and the user of the API needs to know the hierarchy.Moreover the consumer of the API need to write more code in little bit non-standard way(Even though it can be done, but will be little messy). Think this from a different perspective
You have three resources and each has its own identity.So if we refactor the above URI's it will looks like below (I am demonstrating only GET)
User Resource:
Get users list
GET example.com/api/users
Get specific user
GET example.com/api/users/{username}
Report Resource:
Get all reports
GET example.com/api/reports
Get a specific report
GET example.com/api/reports/{report_id}
Photo Resources
All Photos
GET example.com/api/photos
Specific Photo
GET example.com/api/photos/{photo_id}
User All Reports
GET example.com/api/reports?username={userName}
Specific report of a user
GET example.com/api/report?username={userName}&report_id={reportId}
User All Photos
GET example.com/api/photos?username={userName}
User All Photos for a report id (You may not need user Name if report_id is unique irrespective of the user, which will further simplify the URI)
GET example.com/api/photos?username={userName}&report_id={reportId}
All photos of a report
GET example.com/api/photos?report_id={reportId}
This simplifies the understanding and more standard code can be written on the consumer side using this approach.
IMHO you are modelling it well.
Regarding 1 I'd rather go with resource/id rather than query param. But one thing you must have in mind when modelling is the cache mechanism by proxy and so on. So do not forget the headers.
I go for query params for filtering and those sorts.
About the login, the credentials should be in the headers, and no specific resource is needed. Just apply per resource security.
I don't see anything wrong with your scheme.
Most frameworks nowadays use a similar standard for specifying url's (like Django).
In my personal opinion, it makes the URL more readable and a bit nicer for the user.