Google Calender API - Get eventID In a Calender - google-calendar-api

I need to get eventID's of a Calendar. I list events and some information about them but i can not get their ID's. I used this doc: https://developers.google.com/calendar/api/v3/reference/events/list
// Print the next 10 events on the user's calendar.
$calendarId = 'xxxx#group.calendar.google.com';
$optParams = array(
'maxResults' => 100,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => date('c', strtotime("monday -1 week")),
'timeMax' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
$events = $results->getItems();
if (empty($events)) {
print "No upcoming events found.\n";
} else {
//print "Upcoming events:\n";
foreach ($events as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s %s\n", $event->getSummary(), $start);
}
}
}

The method events.list
Returns a response
{
"kind": "calendar#events",
"etag": etag,
"summary": string,
"description": string,
"updated": datetime,
"timeZone": string,
"accessRole": string,
"defaultReminders": [
{
"method": string,
"minutes": integer
}
],
"nextPageToken": string,
"nextSyncToken": string,
"items": [
events Resource
]
}
Which contains a list of Event Resources
An event resource has a field called id.
{
"kind": "calendar#event",
"etag": etag,
"id": string,
....
So depending upon which language you would be using it would just be a matter of looping though each of the items returned by the method and then accessing the id of that event.
C# example.
foreach(var event in response.Items){
Console.WriteLine(event.Id)
}

Related

how to filter only one data with a specific slug in sanity.io?

Data:
[
{
"name": "Gates of Olympus",
"slug": {
"_type": "slug",
"current": "gates-of-olympus"
}
},
{
"name": "Floating Dragon",
"slug": {
"_type": "slug",
"current": "floating-dragon"
}
},
{
"name": "Buffalo King Megaways",
"slug": {
"_type": "slug",
"current": "buffalo-king-megaways"
}
},
{
"name": "Fruit Party",
"slug": {
"_type": "slug",
"current": "fruit-party"
}
}
]
How do I query only objects with slug gates-of-olympus ?
Code:
export const getServerSideProps = async ({params}:any) => {
const query = `*[_type=="game"]{
name,
slug,
}`;
const games = await sanityClient.fetch(query);
return {
props: {
games,
},
};
};
slug is obtained through context (params.game).
I also tried,
*[_type=="game" && slug.current == ${params.game}] but still returns all data.
Wrap ${params.game} with the quotes. Like this "${params.game}". It will work
You get back all the data but the first one or first item in that array of data is the one your searching for so at the end of your query put [0] at the end to get the first value you should be solid eg *[_type=="game" && slug.current == '${params.game}'][0]
Ref
go to this video which is taught by js mastery skip to 1:21:27 he starts explaining how to get the current slug/product https://www.youtube.com/watch?v=4mOkFXyxfsU&t=5153s

API Platform: How to normalize a collection of embedded entities in GraphQL?

I'm trying to make a collection of subresources selectable in GraphQL (with pagination). I'd like to be able to query:
query {
getA(id: '/api/A/1') {
aId
subresources {
totalCount
pageInfo {
endCursor
startCursor
hasNextPage
hasPreviousPage
}
edges {
node {
bId
}
}
}
}
}
and get the result:
{
aId: 1,
subresources: {
"totalCount": XX,
"pageInfo": {
"endCursor": "MQ==",
"startCursor": "MA==",
"hasNextPage": true,
"hasPreviousPage": false
},
edges: [
{
node: {
bId: 11
}
},
{
node: {
bId: 12
}
},
{
node: {
bId: 13
}
}
]
}
}
I'm not using Doctrine at all- I'm using custom data providers. The problem I'm encountering is that even when I return an A entity from DataProvider::getItem() that has an array of B subresources, I get an empty array for subresources in GraphQL. I get the correct data in REST though.
I'm following the instructions given in SymfonyCasts and I found a related API Platform issue, but I'm still having no luck.
I traced through API Platform core and I think it has to do with how the entity is normalized in GraphQL. Specifically, an empty array is returned in ItemNormalizer::normalizeCollectionOfRelations(). However, there's a comment saying "to-many are handled directly by the GraphQL resolver" but I'm not sure what that refers to.
Here's the entity code.
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
graphql: ['item_query', 'collection_query', 'create', 'update', 'delete'],
collectionOperations: ['get', 'post'],
itemOperations: ['get', 'put', 'patch', 'delete'],
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
class A {
#[ApiProperty(identifier: true)]
#[Groups(['read', 'write'])]
public ?int $aId = null,
/** #var B[] */
#[ApiProperty(readableLink: true, writableLink: true)]
#[Groups(['read', 'write'])]
public $subresources = []
}
And:
#[ApiResource(
graphql: ['item_query', 'collection_query', 'create', 'update', 'delete'],
collectionOperations: ['get', 'post'],
itemOperations: ['get', 'put', 'patch', 'delete'],
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
class B {
#[ApiProperty(identifier: true)]
#[Groups(['read', 'write'])]
public ?int $bId = null,
}
My ADataProvider:
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): A {
$bs = $this->bDataProvider->getCollection(B::class, null, []);
return new A(123, $bs);
}
My BDataProvider:
/**
* #return ArrayPaginator<B>
*/
public function getCollection(string $resourceClass, string $operationName = null, array $context = []): ArrayPaginator {
return ArrayPaginator::fromList([new B(11), new B(12), new B(13)]);
}
ArrayPaginator implements IteratorAggregate and PaginatorInterface.
Specifically I see this error:
{
"errors": [
{
"debugMessage": "Collection returned by the collection data provider must implement ApiPlatform\\Core\\DataProvider\\PaginatorInterface or ApiPlatform\\Core\\DataProvider\\PartialPaginatorInterface.",
"message": "Internal server error",
"extensions": {
"category": "internal"
},
"locations": [
{
"line": 29,
"column": 5
}
],
"path": [
"a",
"b"
],
"trace": [
{
"file": "/homedir/core/src/GraphQl/Resolver/Stage/SerializeStage.php",
"line": 100,
"call": "ApiPlatform\\Core\\GraphQl\\Resolver\\Stage\\SerializeStage::serializeCursorBasedPaginatedCollection(array(0), array(5), array(6))"
},
TLDR: How does one use annotations (or YAML) to make attributes that are collections of subresources selectable in GraphQL?
Any help/ideas are appreciated, thanks for reading!
Found a solution: the ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface needs to be implemented by the BDataProvider.
It gets used in the ReadStage of api platform's graphql resolver. Surprisingly, it's found nowhere in the REST resolver, so this won't get called on a REST request.
The only method that needs to be implemented is getSubresource(). My basic first implementation looks like this:
public function getSubresource(string $resourceClass, array $identifiers, array $context, string $operationName = null) {
if ($context['collection']) {
return $this->getCollection($resourceClass, $operationName, $context);
}
$id = // get your id from $identifiers;
return $this->getItem($resourceClass, $id, $operationName, $context);
}
This isn't found in the docs unfortunately, but there are a few pulls (1, 2) open to add it.

How to filter google calendar REST API events by attendee's email

I'm accessing Google Calendar REST API for Calendar Events, trying to figure out a proper notation for q parameter, to filter all events where one of the attendees is identified by email (let's say foo#bar.com)
I've tried: q=attendee.email:foo#bar.com, q=attendee.email=foo#bar.com, q=attendees.email=foo#bar.com, q=attendees.email="foo#bar.com"...
but with no results (empty list, once the q parameter is filled in)
Is it supported at all?
Is there a list of valid q parameter fields to filter by?
You cannot use any Calendar API call to directly search for attendees.
However, you can achieve this by code. You have to list all the events, loop through them and filter the events if the email you wrote coincides with the email in the attendees. For example:
function searchEvents() {
var calendarId = "primary";
var email = "test#email.com";
var result = Calendar.Events.list(calendarId).items;
for (var i = 0; i < result.length; i++){
if (result[i].attendees != undefined){ //Filters out the events without attendees
for (var j = 0; j < result[i].attendees.length; j++){
if (result[i].attendees[j].email == email){
Logger.log(result[i]); //It returns all the event information
}
}
}
}
}
The full resource object returned:
{
"kind": "calendar#calendarListEntry",
"etag": etag,
"id": string,
"summary": string,
"description": string,
"location": string,
"timeZone": string,
"summaryOverride": string,
"colorId": string,
"backgroundColor": string,
"foregroundColor": string,
"hidden": boolean,
"selected": boolean,
"accessRole": string,
"defaultReminders": [
{
"method": string,
"minutes": integer
}
],
"notificationSettings": {
"notifications": [
{
"type": string,
"method": string
}
]
},
"primary": boolean,
"deleted": boolean,
"conferenceProperties": {
"allowedConferenceSolutionTypes": [
string
]
}
}
REFERENCES:
Events List
List Resource
The "q" parameter is working like a text search in event list.
Free text search terms to find events that match these terms in the
following fields: summary, description, location, attendee's
displayName, attendee's email. Optional.
It possible to search events with specified email:
calendar.events.list(
{
q: 'attendee#email.test',
calendarId: 'primary',
timeMin: new Date().toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime',
}
It should return events where 'attendee#email.test' is specified

symfony entity createAt and updateAt type is datetime, when i wrote api,the result is bad

I am sorry for the title being so non-descriptive but the question I am asking is way to broad to fit in 10 words.
when i use symfony entity createAt and updateAt type is datetime, when i wrote api,the result is bad.I not want change createAt and updateAt to string type.thanks
entity defiend is like this:
/**
* #var \DateTime
*
* #ORM\Column(name="updateAt", type="datetime", options={"comment":"更新时间"})
*/
private $updateAt;
the method in repository :
public function getList($userId, $isMime)
{
$qb = $this->createQueryBuilder('c')
->select('c.title,c.nodeName as node_name, c.node, c.updateAt as datetime');
if($isMime == 0){
$qb->leftJoin(ApprovalInformation::class,'a','WITH','a.flowId = 11 and a.itemId = c.id');
$qb->where('a.approverId = :uid');
}else{
$qb->where('c.userId = :uid');
}
$qb->setParameter('uid', $userId);
return $qb->getQuery()->getResult();
}
controller
$list = $cardRepo->getList($this->user->getId(), $mime);
return $this->json([
'code' => 1,
'msg' => '获取成功',
'data' => $list
]);
{
"code": 1,
"msg": "获取成功",
"data": [
{
"title": "测试报告",
"node_name": "处长批示",
"node": 11,
"datetime": {
"date": "2019-05-07 19:04:00.000000",
"timezone_type": 3,
"timezone": "Asia/Shanghai"
}
},
{
"title": "测试报告2222",
"node_name": "处长审批",
"node": 2,
"datetime": {
"date": "2019-05-07 19:28:14.000000",
"timezone_type": 3,
"timezone": "Asia/Shanghai"
}
}
]
}
my except result like is:
{
"code": 1,
"msg": "获取成功",
"data": [
{
"title": "测试报告",
"node_name": "处长批示",
"node": 11,
"datetime": "2019-05-07 19:04:00",
},
{
"title": "测试报告2222",
"node_name": "处长审批",
"node": 2,
"datetime": "2019-05-07 19:28:14",
}
]
}
I want to know an efficient solution.thanks
You are using $this->json() in your controller which will serialize your entity using json_encode(). This is what is causing the datetime to be returned like this:
$ php -a
php > echo json_encode(new DateTime());
{"date":"2019-05-07 14:20:22.137677","timezone_type":3,"timezone":"UTC"}
There is multiple ways around this. You can create an array from your data before calling $this->json():
return $this->json(
array_map(
function ($entity) {
return [
'title' => $entity->getTitle(),
...
'updateAt' => $entity->getUpdateAt()->format('Y-m-d H:i:s'),
];
},
$list
)
);
Alternatively you could use the Symfony Serializer: https://symfony.com/doc/current/components/serializer.html#serializing-an-object
If you use the Serializer, make sure you also have the DateTimeNormalizer registered.
Just do it following code in your getUpadateAt function in entity:
return $this->updateAt->format('Y-m-d h:I:s);

API Gateway and DynamoDB PutItem for String Set

I can't seem to find how to correctly call PutItem for a StringSet in DynamoDB through API Gateway. If I call it like I would for a List of Maps, then I get objects returned. Example data is below.
{
"eventId": "Lorem",
"eventName": "Lorem",
"companies": [
{
"companyId": "Lorem",
"companyName": "Lorem"
}
],
"eventTags": [
"Lorem",
"Lorem"
]
}
And my example template call for companies:
"companies" : {
"L": [
#foreach($elem in $inputRoot.companies) {
"M": {
"companyId": {
"S": "$elem.companyId"
},
"companyName": {
"S": "$elem.companyName"
}
}
} #if($foreach.hasNext),#end
#end
]
}
I've tried to call it with String Set listed, but it errors out still and tells me that "Start of structure or map found where not expected" or that serialization failed.
"eventTags" : {
"SS": [
#foreach($elem in $inputRoot.eventTags) {
"S":"$elem"
} #if($foreach.hasNext),#end
#end
]
}
What is the proper way to call PutItem for converting an array of strings to a String Set?
If you are using JavaScript AWS SDK, you can use document client API (docClient.createSet) to store the SET data type.
docClient.createSet - converts the array into SET data type
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName:table,
Item:{
"yearkey": year,
"title": title
"product" : docClient.createSet(['milk','veg'])
}
};

Resources