In the Google Calendar API, how do I determine if a calendar is google-created calendar, or a user-created worskpace calendar - google-api

I need a way to distinguish a google-created calendar (ex. "Holidays in United States") from a user-created calendar (ex. "Engineering Department") in the Google Calendar API. There doesn't seem to be a distinct field for this, so I've been trying to find a pattern in the calendar's fields. From the CalendarList API:
{
...
"items": [
{
"kind": "calendar#calendarListEntry",
"etag": "\"1616104281883000\"",
"id": "en.usa#holiday#group.v.calendar.google.com",
"summary": "Holidays in United States",
"description": "Holidays and Observances in United States",
...
},
{
"kind": "calendar#calendarListEntry",
"etag": "\"1623344030696000\"",
"id": "c_g3s8ze0hkg2mc6kabr33f6r0ro#group.calendar.google.com",
"summary": "Engineering Department",
...
}
]
It seems like the only differentiating pattern is in the structure of the id field. The Google-created calendars have a readable email username, and the email domain is group.v.calendar.google.com. The user-created calendar on the other hand has a seemingly random string of characters as the username, and the email domain is group.calendar.google.com (notice the .v is missing).
This is a single example, but from the other examples I've seen the pattern is consistent. I haven't been able to find this pattern explicitly stated anywhere in the Google Calendar API docs, but maybe I'm missing something. Is this pattern explicitly stated anywhere? Or am I going about this wrong, and should be using a different feature of the API to distinguish these cases?

Related

How i can get list of popular youtube channels per each country?

How i can get list of popular youtube channels per each country?
this service find solution
https://www.channelcrawler.com/eng/results2/281574
I tried youtube api but i didn't find, anyone know solution?
As mentioned, is not possible to get this information using the YouTube API directly, even in the FAQ of the page you shared says:
The Channel Crawler was made to discover new YouTube channels, based on your search criteria.
and:
The Channel Crawler uses advanced data collection methods in order to collect channel information from YouTube and store it in the database. Basically, it just checks the liked videos and comment sections of channels that are already in the database, in order to add more channels to it. You can also manually add a channel.
Following the highlighted information, I have this idea and you can try it too:
Use the search endpoint for search channels in a specific country and in a specific videoCategory, then, with the channelId returned in the results of the search, use the channel endpoint for get their country1.
1 take into account that some channels doesn't have the country value; in this case, you have to set another criteria(s) for determine whether the channel matches with your requirements.
Example:
Use the search endpoint for search channels in country/region Pakistan and in the videoCategory Sports - test it here:
URL:
https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&order=videoCount&q=Sports&regionCode=PK&key=[YOUR_API_KEY]
The results of this request are as follows:
{
"kind": "youtube#searchListResponse",
"etag": "0C7hSI3oNXJt66PsERuviVQcLCo",
"nextPageToken": "CAUQAA", // Remember the nextPageToken for get the next results.
"regionCode": "PK", // Region queried.
"pageInfo": {
"totalResults": 1000000, // Look the amount of data you have to check, filter and debug.
"resultsPerPage": 5 // Set "maxResults" parameter to "50" for get more results per page.
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "iSwEnBs_yV6lOIBubmRXVwjjujQ",
"id": {
"kind": "youtube#channel", // Make sure that this item is actually an channel.
"channelId": "UCo2TvjBHS1BtyIkeGGTMe6w"
},
"snippet": {
"publishedAt": "2018-07-28T18:34:04Z",
"channelId": "UCo2TvjBHS1BtyIkeGGTMe6w", // Use this value for the "channel" endpoint.
"title": "ONTime Sports",
"description": "قناة اون تايم سبورت واحدة من مجم...",
"thumbnails": { [thumbnails here...] },
"channelTitle": "ONTime Sports",
"liveBroadcastContent": "upcoming",
"publishTime": "2018-07-28T18:34:04Z"
}
},
[other results here...]
]
}
Use channel endpoint for get the channel detailed information - in this case, their country - test it here:
URL - using the channelId UCo2TvjBHS1BtyIkeGGTMe6w - obtained from the previous search results:
https://youtube.googleapis.com/youtube/v3/channels?part=id%2Csnippet&id=UCo2TvjBHS1BtyIkeGGTMe6w&key=[YOUR_API_KEY]
The results of this request are as follows:
{
"kind": "youtube#channelListResponse",
"etag": "8BfUXxlAEBLe7lBmih1JXUwZ394",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "AFk5NCl9393ui58WyRf7WljoatE",
"id": "UCo2TvjBHS1BtyIkeGGTMe6w",
"snippet": {
"title": "ONTime Sports",
"description": "large description here...",
"customUrl": "ontimesportseg",
"publishedAt": "2018-07-28T18:34:04Z",
"thumbnails": {[thumbnails here]},
"localized": {
"title": "ONTime Sports",
"description": "large description here..."
},
"country": "EG" // This is the regionCode of the country this channels has provided.
}
}
]
}
Here, you can see that the value "country" for this channel is "EG" = Egypt2.
Then, repeat these steps with all countries and videoCategory for each country.
Considerations:
As I tested, the type parameter in search is not working as one might expect, in this case (for get channels only), use the order=viewCount combination of parameter=value. Even with this combination, make sure to check that the value of the kind attribute is: youtube#channel. Also, I search the videoCategory using its name, no its id - as it should be -, but, the API is not perfect, that's why I used the name of the videoCategory.
Even specifiyng the region parameter with a valid country, you might get results that are either from another countries or doesn't have the country attribute and value at all = and that's due the channel's popularity in the given country and public channel information. A simple example could be: ESPN, they probably have a YouTube channel for each country, but, their main channel is the most popular in all countries, so, in this case, you'll get the ESPN channel in english and that might differ from your expected results. You have to work with what YouTube provides.
As you notice, there are too many channels/results to debug, so, make sure to provide more filters and set your queries/search criteria and (once you get the desired results), store the valid results in a database or similar.
If you know specific channels that you know are popular in a given country, but, when you query that channel using the YouTube Data API, it doesn't bring the country value, you have to save that channel manually in your database and/or collect more information for automatically set if a channel is from a given country - this point is very related to my point # 2.

how to Detect Marketing and Role based emails programmatically?

I have requirements where I would have to distinguish emails whether it is regular email, Marketing email, or Role based email.
Marketing Emails: Emails that correspond to a marketing campaign. Typically sent to a batch of users and composed with tools like
MailChimp, etc...
Role-Based Emails: Emails addresses that are not associated with a particular person, but rather with a company, department, position, or
group of recipients (ex: noreply#, marketing#, support#, etc).
Can I identify this by email header information? Or is there any other way to achieve this?
Technology using:
Gmail API: to get email information
Spring boot: to process emails
By using the Gmail API you can retrieve the emails by using the following request:
GET https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/{id}
Which will end up returning the body of a Message with the following similar structure:
{
"id": ID,
"threadId": THREAD_ID,
"labelIds": [
"CATEGORY_PROMOTIONS",
"UNREAD",
"INBOX"
],
"payload": {
"headers": [{
"name": "Reply-To",
"value": "NAME \u003cnewsletter#email.com\u003e"
},
{
"name": "Subject",
"value": "Week 9 Newsletter"
},
{
"name": "From",
"value": "NAME \u003csupport#email.com\u003e"
},
"body": {
"size": SIZE,
"data": ""
}
},
}
So depending on how you want to process these afterwards, you can use some of the following fields from the returned email:
labelIds - this field will contain all the labels attached to the incoming email which means that (depending on the settings you have for your inbox) you can easily check this email for instance as being a promotional email because of the CATEGORY_PROMOTIONS label attached to it;
Reply-To header - you can retrieve the email address here and later analyze it;
Subject header - assuming you have a list of keywords set up, you can search the subject of the email and later mark it based on the results;
From header - you can retrieve this email address here and again, based on a list of keywords, you can decided of which type this email is.
Reference
Gmail API Message Resource.

How to fetch user's email address associated with Apple Pay Account from Apple Pay using JavaScript

I wanted to know if Apple has an API which we can use to fetch user's email address associated with apple pay account.
FYI I am using apple pay js (ApplePaySession) for apple pay.
Or is there another way to fetch user's email address from Apple pay in JavaScript.
Thank You!
The email address is provided within the onpaymentauthorized callback of your ApplePaySession.
Note: It is an inherited property, so it may be somewhat difficult to find in your developer console (in Chrome you've got to drill down into the event's __proto__ property).
You must specifically ask for the email address by including a requiredShippingContactFields property in your payment request:
requiredShippingContactFields: [
'phone',
'email'
]
And the email address will be available like so:
var session = new ApplePaySession(2, myPaymentRequest);
session.onpaymentauthorized = function(event){
console.log(event.payment.shippingContact.shippingAddress);
};
Once the user authorizes the transaction, you will get the shippingContact Object like this:-
{
"locality": “India",
"country": "India",
"postalCode": "95014-2083",
"administrativeArea": "CA",
"emailAddress": “sachin#example.com”,
"familyName": “Tendulkar",
"addressLines": [
"1 Infinite Loop"
],
"givenName": “Sachin",
"countryCode": "INDIA",
"phoneNumber": "(408) 555-5555"
}
from this object you can access the email id.

How to uniquely identity a Person resource in Google People API response from a particular user?

Google People API, unlike Google Plus API doesn't provide an unique id for each Person resource in the response.
Why has this been deprecated/removed and how to uniquely identify a Person in an user's contacts list without an id?
In short, use resourceName as an ID.
The Google People API is the user's list of contacts and have IDs specific to the user. They can create contacts that only have a mailing address or only have a name and no contact info. There is no way for Google to logically collate all of these contacts across all of the Google Contacts users.
Specific contacts or a user have a resourceName field that uniquely identifies that resource (contact) for the authenticating user. You basically want to use that as an id. This is the value you for use, for example, to query People.get.
This is part of an example response of a single contact from People.connections:
{
"resourceName": "people/103710953423417258027",
"etag": "qwApd98gduQ=",
"metadata": {
"sources": [{
"type": "CONTACT",
"id": "1",
"etag": "#rj+KMFHVyHY="
}, {
"type": "PROFILE",
"id": "103710953423417258027",
"etag": "#4eZfef/IuMFw="
}],
"objectType": "PERSON"
},
...
}
resourceName is essentially the "id" of that contact and then in the metadata field it lists the sources the contact data comes from. E.g. CONTACT is for a Google Contacts entry where the user has manually entered name/phone/email/etc. PROFILE is a Google Profile, commonly with Google+ data.
The Person resource docs are a great place to learn more about these values.

Pull public event data from Google Calendar

I may be over thinking this a bit. On my web site, I would like to user certain data from my public google calendar. My plan is to pull it on the server side so I can do things like process it, cache it and format it the way I want.
I've been looking at using the Google Api libraries, but I can't get past any of the authorization hurdles. A service account sounds like what I really want, but I'm having trouble wrapping my head around how that works in this situation.
The old GDATA apis would be ok, but I'm not very keen on using them because they look fairly deprecated at this point by the newer libraries.
Since it is all public data, I'm hoping there is a simpler way to get to the event data that I'm looking for.
In case it matters, my site is Asp.Net (MVC).
Update
Ok, I was definitely way over thinking it. See my answer.
Now that RSS has been removed from Google Calendar, I've been in search of an easy replacement. I dug around and found the following in the Google Calendar API that seems to do the trick: calendar.events.list
Calendar Events List in Google API Explorer is a good place to get started with the different parameters and options - and it'll build you an example request string. You can see that I specified a minimum time of 2/5/2016, sort it by the start time, and show deleted events.
GET https://www.googleapis.com/calendar/v3/calendars/[CALENDAR ID HERE]/events?
orderBy=startTime&showDeleted=true&singleEvents=true&
timeMin=2016-02-05T00%3A00%3A00Z&key={YOUR_API_KEY}
Results are in JSON so you can parse it in your favorite programming language, ASP.NET or whatever. Result looks like:
{
"kind": "calendar#events",
"etag": "\"123456789123456\"",
"summary": "My Public Calendar",
"updated": "2016-01-29T14:38:29.392Z",
"timeZone": "America/New_York",
"accessRole": "reader",
"defaultReminders": [ ],
"items": [ {
"kind": "calendar#event",
"etag": "\"9876543210987654\"",
"id": "sfdljgsdkjgheakrht4sfdjfscd",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=sdgtukhysrih489759sdkjfhwseihty7934hyt94hdorujt3q95uy689u9yhfdgnbiwe5hy",
"created": "2015-07-06T16:21:59.000Z",
"updated": "2015-07-06T16:21:59.329Z",
"summary": "In-Service Day",
"location": "Maui, HI",
"creator": {
"email": "abra#cadabra.com",
"displayName": "Joe Abra"
},
"organizer": {
"email": "cadabra.com_sejhrgtuiwerghwi4hruh#group.calendar.google.com",
"displayName": "My Public Calendar",
"self": true
},
"start": {
"date": "2016-02-08"
},
"end": {
"date": "2016-02-09"
},
"transparency": "transparent",
"iCalUID": "isdt56y784g78ty86tgsfdgh#google.com",
"sequence": 0
},
{
...
}]
}
One good answer to this (the one I'm going with) is to simply use the calendar's public address to get the data. This is an option that I had forgotten about and it works fine for this particular situation.
You can find the url for the data if you go to the settings for a particular calendar and pick the format you want (I went with xml for this situation.)
The data that you get out of this service is very human-reader optimized, but I can make it work for what I'm doing.

Resources