List all folders that are direct children Google drive API - php

I'm trying to list all folders that are at the root of a teamdrive using the google api php client. The perans i'm using look like this:
$optParams = array(
'driveId' => "<ID OF TEAM DRIVE>",
'pageSize' => 100,
'includeItemsFromAllDrives' => true,
'supportsAllDrives' => true,
'corpora' => "drive",
'fields'=>'nextPageToken, files(id, name)',
'q' => ["mimeType = 'application/vnd.google-apps.folder'", "'<ID OF TEAM DRIVE>' in parents"]
);
The problem is that this lists all the sub-folders as well and not just the folders in the root of that team drive.
This feels like it should be easy but i'm probably missing something obvious.

I did solve this by removing DriveId, copora and the mimeType.
My guess is that this statement (which I did not find a documentation on) means one thing OR another thing and not one thing AND another thing.
["mimeType = 'application/vnd.google-apps.folder'", "'<ID OF TEAM DRIVE>' in parents"]
So what worked for me was:
$optParams = array(
'pageSize' => 100,
'includeItemsFromAllDrives' => true,
'supportsAllDrives' => true,
'fields'=>'nextPageToken, files(id, name)',
'q' => "'<DRIVE ID>' in parents"
);

user3477740, you were very close.
Place your entire query inside a single string like below, and (I strongly suggest) separate your logic inside parenthesis:
'q' => "(trashed = false) and (mimeType = 'application/vnd.google-apps.folder') and ('<DRIVE ID>' in parents)"
And thanks to you for showing me the easy way to reference google drive children within a google drive folder - it's not well documented in Google Drive V3

Related

Google TeamDrive getChildren of a teamDriveID PHP

I'm using PHP and the following call to retrieve the top-level TeamDrive folders.
$service->teamdrives->listTeamdrives()->getTeamDrives();
Results
TeamDrive1 --- let's say the ID is XXXXXX
TeamDrive2 --- let's say the ID is YYYYYY
TeamDrive1 has a sub-folder called TeamDrive1Sub1 (ID is SSSSS)
then TeamDrive1Sub1 (ID PPPPP) also has a sub-folder etc
I've tried to use the Drive REST API files:List - but this does not seem to work...
I need to find the children "x" levels deep, how do I do that? Maybe some other interface call such as the one I'm using above $service->teamdrives->listTeamdrives()->getTeamDrives(); which allows me to start at the ID XXXXXX and retrieve it's children
Found my own answer, but there's probably a better way... if you have the ID of a teamdrive folder and want to get the sub-folders - here's what I have for the PHP code
//- first we need to get the $teamDriveId - using the /files/get & the $folderId we passed in
$folderId = "XXXXXX" // from above
$optParams = array(
'supportsTeamDrives' => true,
);
$results = $service->files->get($folderId, $optParams);
$teamDriveId = $results["teamDriveId"];
// now we can get the sub-folders (if there are any)
$params = [
'q' => "'{$folderId}' in parents and trashed = false and mimeType = 'application/vnd.google-apps.folder'",
'pageSize' => $pageSize,
'corpora' => 'teamDrive',
'includeTeamDriveItems' => true,
'supportsTeamDrives' => true,
'teamDriveId' => $teamDriveId, // this must be the parent Id
'orderBy' => 'name',
];
$results = $service->files->listFiles($params);
Hope this helps someone

Trying to Stream music while connecting Nexmo NCCO

I tried to stream music while connecting the agent into the phone call.
but it's stuck in the stream and then calling.
anyone used it before? I'm sure that's impossible to make this.
Code:
$array[] = array(
"action" => "stream",
"streamUrl" => array("https://pbx.makeapp.co.il/wait.mp3"),
);
$array[] = array(
"action" => "connect",
"eventType" => "synchronous",
"eventUrl" => array("https://pbx.makeapp.co.il/config.json?step=1"),
"timeout" => 30,
"from" => "YOUR_NEXMO_PHONE",
"endpoint" => array(array(
"type" => "sip",
"uri" => "sip:your_sip#sip.antisip.com",
)
)
);
You are correct, it is not possible to have 2 actions running at the same time using an NCCO. When you add a stream action to the start of your NCCO, this must be completed before it moves onto the next action. An NCCO array is actioned from top to bottom, and only moves onto the next action when the current one has finished. You can find out some more info in the concepts of an NCCO section of the documentation: https://developer.nexmo.com/voice/voice-api/ncco-reference

Accessing a child node using JSON within PHP and file_get_contents()

OK I am stumped.
I have tried numerous different approaches and I've spent the best part of a good few hours searching to no avail to my exact situation, that or I am tired and blind.
Here is the raw json pulled from a URI using file_get_contents():
{"id":"XXX","name":"Customer1","os":"CentOS Linux 7.3.1611 Core","cpu_type":"Intel(R) Xeon(R) CPU E3-1245 V2 # 3.40GHz","networking_v4":[{"addr":"xxx.xxx.xxx.xxx","if":"eth0"}],"networking_v6":[{"addr":"xxxx","if":"eth0"},{"addr":"xxxx","if":"eth0"}],"agent_version":0.96,"status":"up","last_update":1505949230,"first_update":1500588943,"notifications_count":8,"ip_whois":{"ip":"xxx.xxx.xxx.xxx","hostname":"xxx","city":"Garwood","region":"New Jersey","country":"US","loc":"xxx","org":"AS20473 Choopa, LLC","postal":"xxx"},"additional_fields":[{"value":"xxx","key":"Datacenter"},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""}]}
As you can see its a pretty simple request and I have every bit of data except those nested within networking_v4 and networking_v6.
I tried to access those like so:
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
Here is the full snapshot of code in its entirety:
$content = file_get_contents($url);
$json = json_decode($content);
$server_lastupd = $json->last_update;
$server_firstupd = $json->first_update;
$server = array(
'id' => $json->id,
'name' => $json->name,
'os' => $json->os,
'cputype' => $json->cpu_type,
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
'status' => $json->status,
'lastupd' => $json->$server_lastupd,
'firstupd' => $json->$server_firstupd,
'notifications' => $json->notifications_count,
'ip' => $json->ip_whois->ip,
'hostname' => $json->ip_whois->hostname,
'city' => $json->ip_whois->city,
'region' => $json->ip_whois->region,
'country' => $json->ip_whois->country,
'loc' => $json->ip_whois->loc,
'org' => $json->ip_whois->org,
'postal' => $json->ip_whois->postal,
'dctag' => $json->additonal_fields->dctag,
'source' => "XXX"
);
return $server;
So my issue is I appear to be unable to access the child content within networking_v4 and networking_v6.
Any help on this would be massively appreciated, its stumped me for the best part of 6 hours last night and a few more today, so I give in, someone please show me the light!
Many thanks :)
It looks like those are nested in arrays from the [{"key':"value"},{"key":"value"}] square brackets. have you tried
ipv4 => $json->networking_v4[0]->addr,
Try $json->networking_v4[0]->addr.
Both the networking_v4 and the networking_v6 keys point to arrays, so you need to pick which index you want to look at. The former only has one element, so it's easy to pick index 0, but the latter has multiple elements, so you'll need to figure out which one you want.

Google Analytics SEO - PHP API

I have a PHP file which give's me google analytics data, such as pageviews, Top Pages, or Organic Data simple stuff.
Now I neet to get Stuff from the SEO Part.
For example: TOP 50 Search Keywords (with Impression and Clicks)
I can't find any help in the API how to get these values.
this is a example of my api call:
$params = array(
'dimensions' => array('date', 'pagePath', 'pageTitle'),
'metrics' => array('sessions', 'pageviews'),
'sort' => '-ga:sessions',
'filters' => null,
'startdate' => $startdate,
'enddate' => $enddate,
'startindex' => null,
'limit' => 25,
'mapping' => array('pagepath' => 'pagepath', 'pagetitle' => 'pagetitle', 'sessions' => 'visits', 'pageviews' => 'pageviews'),
);
$results = $this->service->data_ga->get($this->profile, $params['startdate'], $params['enddate'], $metrics, $optParams);
The search engine optimization data shown in Google Analytics actually comes from Google Search Console (Webmaster Tools) and is available from the Google Search Console API.
https://developers.google.com/webmaster-tools/?hl=en
You would need to update the Dimensions and Metrics of your query. The traffic dimensions and metrics should be of help.
Below is a simplified query which gets the number of impressions and clicks for various sources and keyword combinations:
$optParams = array(
'dimensions' => 'ga:source,ga:keyword',
'sort' => '-ga:impressions,ga:source',
'filters' => 'ga:medium==organic',
'max-results' => '25');
$metrics = 'ga:impressions,ga:adClicks';
$results = $this->service->data_ga->get(
'ga:XXXX',
'today',
'7daysAgo',
$metrics,
$optParams);
Your code must have some mapping that it does from the values in $param field to the actual dimensions and metric names. I would also encourage you to play around with the query explorer to get a field of what queries are possible.

understanding ElasticSearch routing

I am trying to use the elasticsearch routing mapping to speed up some queries, but I am not getting the expected result set (not worried about the query performance just yet)
I am using Elastic to set up my mapping:
$index->create(array('number_of_shards' => 4,
'number_of_replicas' => 1,
'mappings'=>array("country"=>array("_routing"=>array("path"=>"countrycode"))),
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
),
'searchAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
)
)
) ), true);
If I understand correctly, what should happen is that each result should now have a field called "countrycode" with the value of "country" in it.
The results of _mapping look like this:
{"postcode":
{"postcode":
{"properties":
{
"area1":{"type":"string"},
"area2":{"type":"string"},
"city":{"type":"string",
"include_in_all":true},
"country":{"type":"string"},
"country_iso":{"type":"string"},
"country_name":{"type":"string"},
"id":{"type":"string"},
"lat":{"type":"string"},
"lng":{"type":"string"},
"location":{"type":"geo_point"},
"region1":{"type":"string"},
"region2":{"type":"string"},
"region3":{"type":"string"},
"region4":{"type":"string"},
"state_abr":{"type":"string"},
"zip":{"type":"string","include_in_all":true}}},
"country":{
"_routing":{"path":"countrycode"},
"properties":{}
}
}
}
Once all the data is in the index if I run this command:
http://localhost:9200/postcode/_search?pretty=true&q=country:au
it responds with 15740 total items
what I was expecting is that if I run the query like this:
http://localhost:9200/postcode/_search?routing=au&pretty=true
Then I was expecting it to respond with 15740 results
instead it returns 120617 results, which includes results where country is != au
I did note that the number of shards in the results went from 4 to 1, so something is working.
I was expecting that in the result set there would be an item called "countrycode" (from the rounting mapping) which there isn't
So I thought at this point that my understand of routing was wrong. Perhaps all the routing does is tell it which shard to look in but not what to look for? in other words if other country codes happen to also land in that particular shard, the way those queries are written will just bring back all records in that shard?
So I tried the query again, this time adding some info to it.
http://localhost:9200/postcode/_search?routing=AU&pretty=true&q=country:AU
I thought by doing this it would force the query into giving me just the AU place names, but this time it gave me only 3936 results
So I Am not quite sure what I have done wrong, the examples I have read show the queries changing from needing a filter, to just using match_all{} which I would have thought would only being back ones matching the au country code.
Thanks for your help in getting this to work correctly.
Almost have this working, it now gives me the correct number of results in a single shard, however the create index is not working quite right, it ignores my number_of_shards setting, and possibly other ones too
$index = $client->getIndex($indexname);
$index->create(array('mappings'=>array("$indexname"=>array("_routing"=>array("required"=>true))),'number_of_shards' => 6,
'number_of_replicas' => 1,
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
),
'searchAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
)
)
) ), true);
I can at least help you with more info on where to look:
http://localhost:9200/postcode/_search?routing=au&pretty=true
That query does indeed translate into "give me all documents on the shard where documents for country:AU should be sent."
Routing is just that, routing ... it doesn't filter your results for you.
Also i noticed you're mixing your "au"s and your "AU"s .. that might mix things up too.
You should try setting required on your routing element to true, to make sure that your documents are actually stored with routing information when being indexed.
Actually to make sure your documents are indexed with proper routing explicitly set the route to lowercase(countrycode) when indexing documents. See if that helps any.
For more information try reading this blog post:
http://www.elasticsearch.org/blog/customizing-your-document-routing/
Hope this helps :)

Categories