[gmail-api]How to get count of Primary Category - gmail-api

How to get the count of the primary category in the gmail inbox. We can get for other categories like social by adding the label id CATEGORY_SOCIAL in the get label api call, but there seems to be no label id 'CATEGORY_PRIMARY'.
There is a CATEGORY_PERSONAL, is it same as primary?

CATEGORY_PERSONAL is not the same as the “Primary” category. The Method: users.labels.get only works for labels which is different from categories. Labels are located at the left of your Gmail inbox and categories are at the top. The other categories are listed in types of labels because labels for those categories are automatically created. Since the “Primary” category doesn’t have a label, you can’t retrieve the information with users.labels.get.
There is another way to retrieve information for categories, which is Method: users.messages.list with parameters: userId = user's email address, maxResults = 500, q = category:primary, however, maximum of messages to return is 500 and you only get an estimated total number of results.
Getting data for Gmail categories, is a product limitation for Gmail API, this request can be promoted for future development through here.
CATEGORY_PERSONAL was part from the now discontinued "Inbox by Gmail".

Related

Convert three modelsto one single query django query

This are my model with some of the fields:
class Advertisers(models.Model):
account_manager_id = models.ForeignKey(AccountManagers, on_delete=models.CASCADE,null=True, db_column='account_manager_id',related_name="advertisers")
class AdvertiserUsers(models.Model):
user_id = models.OneToOneField('Users', on_delete=models.CASCADE,null=True,db_column='user_id', related_name='advertiser_users')
advertiser_id = models.ForeignKey('Advertisers', on_delete=models.CASCADE,null=True,db_column='advertiser_id', related_name='advertiser_users')
class Users(models.Model):
email = models.CharField(unique=True, max_length=100)
I want Id's, user ids and email of all advertisers.
Id's of all user:-
advertiser_ids = advertisers.objects.all() # can get id from here
find user_ids of advertiser_ids:
user_ids = AdvertiserUsers.objects.filter(advertiser_id__in=advertiser_ids) # can get user_id from here
find id and email using this query:
user_ids = Users.objects.filter(id__in=user_ids) # can get email from here
How to make it shorter like directly querying from Advertisers i will be able to get Users models email.
Thankyou in advance
You can filter with:
Users.objects.filter(advertiser_users__advertiser_id__isnull=False).distinct()
The .distinct() [Django-doc] will prevent returning the same Users multiple times.
You can annotate the User objects with the Advertisers primary key, etc:
from django.db.models import F
Users.objects.filter(advertiser_users__advertiser_id__isnull=False).annotate(
account_manager_id=F('advertiser_users__advertiser_id__account_manager_id'),
advertiser_id=F('advertiser_users__advertiser_id')
)
The Users objects that arise from this have a .email attribute (and the other attributes that belong to a Users object), together with a .account_manager_id and an .advertiser_id. That being said, this is probably not a good idea: the way you have modeled this right now, is that a Users object can relate to multiple Advertisers objects, so it makes not much sense to add these together.
You can for each user access the related Advertisers with:
myusers = Users.objects.filter(
advertiser_users__advertiser_id__isnull=False
).prefetch_related(
'advertiser_users',
'advertiser_users__advertiser_id'
).distinct()
for user in myusers:
print(f'{user.email}')
for advuser in user.advertiser_users.all():
print(f' {advuser.advertiser_user.pk}')
Note: normally a Django model is given a singular name, so User instead of Users.
Note: Normally one does not add a suffix _id to a ForeignKey field, since Django
will automatically add a "twin" field with an _id suffix. Therefore it should
be account_manager_id, instead of account_manager.
Advertisers.objects.all().values_list('id','account_manager_id','advertiser_users__user_id',advertiser_users__user_id__email)

Data Category Visibility Issue

I am facing Data Category visibility related issue.
The scenario is i'm following -
I have One Community User which one is using for login into my community.
This User's role is Inheriting Visibility for Category Group from it's parant role and it's Visibility is No categories are visible to parent role and subordinates.
But This User's Permission set have Custom Visibility Permission is like -
All Category Group > child Category > sub child Category
for ex :
All Products > Computers > Laptops
And I am accessing lick bellow query from apex to display related article in community.
Select Id, Title, KnowledgeArticleId, Summary, CreatedDate, UrlName From KnowledgeArticleVersion WHERE Language = 'en_US' and PublishStatus='Online' WITH DATA CATEGORY Products at (Computers__c) limit 10 UPDATE VIEWSTAT
but I am not getting any articles.
getting error like --
Invalid data category name provided: Products. There is no data category matching the given developer name on the data category group: Computers__c
If anyone have solution for this please let me know.
Thank you,
Harsiddhi.
You probably have already figured this out by now, however you need to use the API name for your Group as well, i.e. 'Products' becomes 'Products__c'.
Should be something more like this:
Select Id, Title, KnowledgeArticleId, Summary, CreatedDate, UrlName From KnowledgeArticleVersion WHERE Language = 'en_US' and PublishStatus='Online' WITH DATA CATEGORY Products__c at (Computers__c)
Queries are not dependent on permission sets.
The error in the SOQL query can be looked upon at the query editor. Whenever there is a wrong API name in the query, there comes down an indication in the Query Editor under Developer Console that:
No such column 'field_name' on entity
Thus we can look back at the object fields and relationships and can ensure if the right API name is there.

How to query for User Display Name using LisData.svc SharePoint Online

As you know when using the listdata.svc people picker fields return the userID, not the display name (createdby, modifiedby). I have been looking for a way to query the userprofile svc but have found nothing helpful.
What i am looking to do, is simply convert this ID to their respected display name. I am new to using this listsvc and this was never and issue using empty data views and XSL. If anyone has an example of grabbing list data, and showing the createdby, modifiedby, or a custom people picker field and showing their name not id that would be very helpful.
Thanks in advance
This is a default behavior, for a user field, only Id property is getting returned in the result. To return all the properties of user field $expand query options needs to be applied to the query, for example:
/_vti_bin/ListData.svc/Documents?$expand=CreatedBy,ModifiedBy
In that case the projected field values for CreatedByand ModifiedBy fields (from User Information List) are returned along with the result.
To return a specific user field properties, the $select query option could be specified. For example, the following query returns DisplayName (Title property) of CreatedBy and ModifiedBy fields:
/_vti_bin/ListData.svc/Documents?$select=CreatedBy/Title,ModifiedBy/Title&$expand=CreatedBy,ModifiedBy

Simple query at App Engine Search not working

I have the following data inside an index at Search API. The name and slug fields are TextFields.
Document Id name slug
5946158883012608 Configurations configurations
4820258976169984 Customers customers
6227633859723264 Sites sites
I'm trying a lot of options of querystrings and can't get the right row.
My last tries:
index.search('config')
index.search('~config')
index.search('name:~config')
index.search('slug:~config')
If I try: index.search('customers') I receive one row. But if a remove the last s, then I receive no row.
Can someone please explain me why?
Regards,
Armando

In Facebook graph API how to find which all of your friends like a particular page with detail info?

I'm trying to figure out how to find how many of my friends "like" a particular page
and friends' detailed information such as id, name, and picture.
For example: for a given page ID, how can I look up how many of my friends have already liked the same page for the ID?
I just know that when I use this FQL ==>
SELECT uid FROM page_fan WHERE page_id = 114719705207104 AND uid IN (SELECT uid2 FROM friend WHERE uid1=me())
I only got a list of a friends' uids.
But I'd like to get friend list with name, id, picture, and URL.
Simple, just add another IN to the query
SELECT uid, pic, name, username FROM user WHERE uid in (SELECT uid FROM page_fan WHERE page_id = 114719705207104 AND uid IN (SELECT uid2 FROM friend WHERE uid1=me()))
The UID is the user id you want.
The URL for the user is equal to www.facebook.com/UID or www.facebook.com/USERNAME
Since not every user has a username I advise you to use the first option with the UID.
You have many ways of retrieving the user pic, with the uid you can use the graph api to fetch the pic in various sizes, doing this
https://graph.facebook.com/UID/picture or https://graph.facebook.com/USERNAME/picture
Then adding some get parameters you can configure the size of the pic. You can read more about that here
If you want to keep using FQL for selecting the pic, you have many fields in the User table that return different sizes. You can read more about the user table here and see the available fields for the pic

Resources