Google distance matrix api no longer support several origins? - json

Today I woke up and want to run my code (which was working fine) but I got several errors - Undefined offset errors while looping through the json response obtained after a request containing several origins and destinations has been sent:
$request = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=$OriginUrl&destinations=$DestinationUrl&mode=driving");
$resultdistance = json_decode($request, true);
for($i=0;$i<count($LocationDetails);$i++){
$distanceM = $resultdistance['rows'][$i]['elements'][$i]['distance']['value'];
$distanceKM = $distanceM / 1000;
$TravelDistance = round($distanceKM,1); // Distance from Act 1 and Act 2
$DistanceText = $resultdistance['rows'][$i]['elements'][$i]['distance']['text'];
$TimeToTravelSec = $resultdistance['rows'][$i]['elements'][$i]['duration']['value'];
$TimeToTravelText = $resultdistance['rows'][$i]['elements'][$i]['duration']['text'];
}
I then enter the http request manually in the address bar with several origins and notice that the request has been sent with only one origin:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Hilton+Mauritius+Resort+&+Spa,+Coastal+Road,+Flic+en+Flac,+Mauritius|LAventure+du+Sucre,+B18,+Pamplemousses,+Mauritius&destinations=Cascavelle,+Riviere+Noire+District|Mauritius+Aquarium,+B38,+Camp+Bestel,+Pamplemousses+District,+Mauritius|Blue+Safari+Submarines,+B36,+Trou-aux-Biches,+Mauritius|&mode=driving
Two origins has been sent:
1. Hilton+Mauritius+Resort+&+Spa,+Coastal+Road,+Flic+en+Flac,+Mauritius
2.LAventure+du+Sucre,+B18,+Pamplemousses,+Mauritius
but only the first one has been taken into consideration (see image above or click on the link to send request and see the result) ! A few days ago I was using about 5 origins and it was working Please Help !

I remove the '&' in :
Hilton+Mauritius+Resort+&+Spa,+Coastal+Road,+Flic+en+Flac,+Mauritius
and it works fine.There should not be any '& in the origin's name and destination's names because the parameters are already using the '&' sign and this might cause some problems.

Related

Trying to populate dynamically infoblox domain-name with ruby & json

I'm using this code repo for registering newly provisioned vm's with infoblox providing the next available ip address.
What i want to achieve now, is to get also dynamically the domain-name of the used infoblox network.
I tried to copy list_infoblox_networks.rb into a modified "list_infoblox_domain.rb" with the following code below:
if networks_array.blank?
# get an array of networks from infoblox
network_search_filter = "network?network_view=#{network_view}"
# specify fields to return in payload
return_fields = "&_return_fields=network_view,network,netmask,ipv4addr,extattrs,comment,options"
networks_array = call_infoblox(:get, "#{network_search_filter}" + "#{return_fields}")
$evm.log(:info, "Inspecting networks_array: #{networks_array.inspect}")
networks_array.each do |net|
comment = "#{net['comment']}#" if net['comment']
display_string = "#{comment}#{net['options'][0]},#{net['network_view']}"
dialog_hash[net['options'][0]] = display_string
end
end
The expected result should return:
testlab.local from network 192.168.254.0/24, actual result displays the whole hash with all options. dropdown of available infoblox domains
A call to infoblox gives me the following hash back:
<AEMethod list_infoblox_domain> Inspecting networks_array: [{"_ref"=>"network/ZG5zLm5ldHdvcmskMTAuMC4yMC4wLzI0LzA:10.0.20.0/24/default", "comment"=>"test-netz", "extattrs"=>{}, "ipv4addr"=>"10.0.20.0", "netmask"=>24, "network"=>"10.0.20.0/24", "network_view"=>"default", "options"=>[{"name"=>"dhcp-lease-time", "num"=>51, "use_option"=>false, "value"=>"43200", "vendor_class"=>"DHCP"}]}, {"_ref"=>"network/ZG5zLm5ldHdvcmskMTAuMC4zMC4wLzI0LzA:10.0.30.0/24/default", "comment"=>"zweites test-netz", "extattrs"=>{}, "ipv4addr"=>"10.0.30.0", "netmask"=>24, "network"=>"10.0.30.0/24", "network_view"=>"default", "options"=>[{"name"=>"dhcp-lease-time", "num"=>51, "use_option"=>false, "value"=>"43200", "vendor_class"=>"DHCP"}]}, {"_ref"=>"network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yNTQuMC8yNC8w:192.168.254.0/24/default", "comment"=>"prod netz", "extattrs"=>{}, "ipv4addr"=>"192.168.254.0", "netmask"=>24, "network"=>"192.168.254.0/24", "network_view"=>"default", "options"=>[{"name"=>"broadcast-address", "num"=>28, "use_option"=>true, "value"=>"192.168.254.255", "vendor_class"=>"DHCP"}, {"name"=>"dhcp-lease-time", "num"=>51, "use_option"=>false, "value"=>"43200", "vendor_class"=>"DHCP"}, {"name"=>"domain-name-servers", "num"=>6, "use_option"=>true, "value"=>"192.168.254.10", "vendor_class"=>"DHCP"}, {"name"=>"domain-name", "num"=>15, "use_option"=>true, "value"=>"testlab.local", "vendor_class"=>"DHCP"}, {"name"=>"routers", "num"=>3, "use_option"=>true, "value"=>"192.168.254.1", "vendor_class"=>"DHCP"}]}]
it would be great, if somebody could help me to get this flying!

Script properties becomes corrupt: Failed to save Project Properties for script

Script properties becomes "corrupt" after a call to "PropertiesService.getScriptProperties().setProperties(properties)" in my script. By "corrupt", I mean I can no longer add or edit existing properties in: "File -> Project properties -> Script properties", and when I first try I receive the error message "Failed to save Project Properties for script." I've tried deleting all properties and re-adding them, I tried deleting all browser cache, and I tried minimizing my Properties calls to ensure(?) I'm not exceeding quotas.
After this error, going to "File -> Project properties" results in in a endlessly spinning busy cursor while it tries to load the "Info" tab. Re-loading the spreadsheet allows "File -> Project properties" to properly load, but any edits made to properties in the "Script properties" tab brings back the error and spinning cursor problem.
I've narrowed down the culprit in my script but I cannot figure out why it's causing this problem. In my "onOpen()" method I am building up ~125 properties, and then I set them with one call to "setProperties()". The properties go into Script Properties okay, and they function as expected, but this programmatic setting of script properties is definitely the cause of the "Failed to save Project Properties for script." error message.
Link to a copy of my Google spreadsheet containing the script causing the problem. The 3 calls causing the problem are commented with "SETPROPS", and the call to set the properties is commented with "BROKE!". This problem, or ones similar, have come up in the past but seem to be "fixed" or no longer occur.
The code sequence is as follows:
I clear all script properties with: PropertiesService.getScriptProperties().deleteAllProperties()
I call three methods, each taking a "properties" argument.
Each of these 3 methods does nearly the same thing. They each add key/value pairs to "properties".
After each of the 3 methods is called, I set the properties with:
if (Object.getOwnPropertyNames(properties).length !== 0)
{
PropertiesService.getScriptProperties().setProperties(properties);
}
Here is one of the 3 methods that adds to the "properties" var (initialize with: var properties = {};). The other 3 methods add to the properties variable in the same manner, but operate on different data.
function setScriptPropertiesShipSizesForFaction(properties, factionName)
{
var dataSheetName = factionName + "Data";
var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(dataSheetName);
var shipValues = dataSheet.getRange('B3:D200').getValues();
var index = 0;
while ( (index < shipValues.length) && (shipValues[index][0] != "") )
{
var key = '_shipSize_' + normalize(shipValues[index][0]);
var value = shipValues[index][2];
properties[key] = value;
index++;
}
}
I believe I am not exceeded any Google script quota. I do not get any error messages from the call to "setProperties", and I do not see any errors in Google's Stackdriving Logging. At the bottom of this post I have a list of what I am setting in ScriptProperties. It's logging output, with syntax: key=value.
_shipSize_ArquitensCC=S
_shipSize_ArquitensLC=S
_shipSize_AssaultFrigateMk2A=M
_shipSize_AssaultFrigateMk2B=M
_shipSize_CR90-A=S
_shipSize_CR90-B=S
_shipSize_GR-75CombatRetrofits=S
_shipSize_GR-75MediumTransports=S
_shipSize_Gladiator1=S
_shipSize_Gladiator2=S
_shipSize_GozantiAssault=S
_shipSize_GozantiCruisers=S
_shipSize_HammerheadScout=S
_shipSize_HammerheadTorpedo=S
_shipSize_ISD1=L
_shipSize_ISD2=L
_shipSize_ISDCymoon=L
_shipSize_ISDKuat=L
_shipSize_InterdictorCombat=M
_shipSize_InterdictorSuppression=M
_shipSize_MC30cScout=S
_shipSize_MC30cTorpedo=S
_shipSize_MC75ArmoredCruiser=L
_shipSize_MC75OrdnanceCruiser=L
_shipSize_MC80AssaultCruiser=L
_shipSize_MC80BattleCruiser=L
_shipSize_MC80CommandCruiser=L
_shipSize_MC80StarCruiser=L
_shipSize_Nebulon-BEscort=S
_shipSize_Nebulon-BSupport=S
_shipSize_PeltaAssault=S
_shipSize_PeltaCommand=S
_shipSize_QuasarFire1=M
_shipSize_QuasarFire2=M
_shipSize_Raider1=S
_shipSize_Raider2=S
_shipSize_Victory1=M
_shipSize_Victory2=M
_upgradeKeyPrefix_EmpireDEFENSIVE 2=6.0
_upgradeKeyPrefix_EmpireDEFENSIVE=5.0
_upgradeKeyPrefix_EmpireEXPERIMENTAL 2=8.0
_upgradeKeyPrefix_EmpireEXPERIMENTAL=7.0
_upgradeKeyPrefix_EmpireFLEET COMMAND=9.0
_upgradeKeyPrefix_EmpireFLEET SUPPORT=10.0
_upgradeKeyPrefix_EmpireION CANNONS=11.0
_upgradeKeyPrefix_EmpireOFFENSIVE 2=13.0
_upgradeKeyPrefix_EmpireOFFENSIVE=12.0
_upgradeKeyPrefix_EmpireOFFICER=4.0
_upgradeKeyPrefix_EmpireORDNANCE=14.0
_upgradeKeyPrefix_EmpireSUPPORT TEAM=15.0
_upgradeKeyPrefix_EmpireTITLE=3.0
_upgradeKeyPrefix_EmpireTURBOLASER 2=17.0
_upgradeKeyPrefix_EmpireTURBOLASER=16.0
_upgradeKeyPrefix_EmpireWEAPONS TEAM 2=19.0
_upgradeKeyPrefix_EmpireWEAPONS TEAM=18.0
_upgradeKeyPrefix_RebelDEFENSIVE 2=7.0
_upgradeKeyPrefix_RebelDEFENSIVE=6.0
_upgradeKeyPrefix_RebelFLEET COMMAND=8.0
_upgradeKeyPrefix_RebelFLEET SUPPORT=9.0
_upgradeKeyPrefix_RebelION CANNONS=10.0
_upgradeKeyPrefix_RebelOFFENSIVE=11.0
_upgradeKeyPrefix_RebelOFFICER 2=5.0
_upgradeKeyPrefix_RebelOFFICER=4.0
_upgradeKeyPrefix_RebelORDNANCE 2=13.0
_upgradeKeyPrefix_RebelORDNANCE=12.0
_upgradeKeyPrefix_RebelSUPPORT TEAM=14.0
_upgradeKeyPrefix_RebelTITLE=3.0
_upgradeKeyPrefix_RebelTURBOLASER 2=16.0
_upgradeKeyPrefix_RebelTURBOLASER=15.0
_upgradeKeyPrefix_RebelWEAPONS TEAM=17.0
_upgradeSize_BailOrgana=ML
_upgradeSize_DisposableCapacitors=SM
_upgradeSize_GovernorPryce=ML
_upgradeSize_HardenedBulkheads=L
_upgradeSize_StrategicAdviser=L calculatedDataSheetName=Calculated Data cellCommander=E2 colEmpirePlayerNames=1 colRebelPlayerNames=8
colShipNames=2 colSquadNames=2 colUpgradesStart=3
colVariableUpgradesEndEmpire=19 colVariableUpgradesEndRebel=17
colVariableUpgradesStartEmpire=5 colVariableUpgradesStartRebel=6
disabledBgColor=#999999 enabledBgColor=#93c47d
factionNameEmpire=Empire factionNameRebel=Rebel
indexFleetSheetsStart=3
multipleIconUpgrade_BoardingEngineers=OFFENSIVE,WEAPONS TEAM
multipleIconUpgrade_BoardingTroopers=OFFENSIVE,WEAPONS TEAM
multipleIconUpgrade_ChamSyndulla=OFFENSIVE,WEAPONS TEAM
multipleIconUpgrade_DarthVader=OFFENSIVE,WEAPONS TEAM
multipleIconUpgrade_JynErso=OFFENSIVE,WEAPONS TEAM playersPerTeam=3
rowPlayerNamesStart=7 rowShipsEnd=17 rowShipsStart=6
rowSquadNamesEnd=44 rowSquadNamesStart=21 rowUpgradeNames=5
sheetNameSystemTracking=Systems Tracking sheetNameTeamStatus=Team
Status upgradeKeyPrefix=_upgradeKeyPrefix_
upgradeKeyPrefixEmpireDEFENSIVE 2=6.0
upgradeKeyPrefixEmpireDEFENSIVE=5.0
upgradeKeyPrefixEmpireEXPERIMENTAL 2=8.0
upgradeKeyPrefixEmpireEXPERIMENTAL=7.0 upgradeKeyPrefixEmpireFLEET
COMMAND=9.0 upgradeKeyPrefixEmpireFLEET SUPPORT=10.0
upgradeKeyPrefixEmpireION CANNONS=11.0
upgradeKeyPrefixEmpireOFFENSIVE 2=13.0
upgradeKeyPrefixEmpireOFFENSIVE=12.0
upgradeKeyPrefixEmpireOFFICER=4.0 upgradeKeyPrefixEmpireORDNANCE=14.0
upgradeKeyPrefixEmpireSUPPORT TEAM=15.0
upgradeKeyPrefixEmpireTITLE=3.0 upgradeKeyPrefixEmpireTURBOLASER
2=17.0 upgradeKeyPrefixEmpireTURBOLASER=16.0
upgradeKeyPrefixEmpireWEAPONS TEAM 2=19.0
upgradeKeyPrefixEmpireWEAPONS TEAM=18.0
upgradeKeyPrefixRebelDEFENSIVE 2=7.0
upgradeKeyPrefixRebelDEFENSIVE=6.0 upgradeKeyPrefixRebelFLEET
COMMAND=8.0 upgradeKeyPrefixRebelFLEET SUPPORT=9.0
upgradeKeyPrefixRebelION CANNONS=10.0
upgradeKeyPrefixRebelOFFENSIVE=11.0 upgradeKeyPrefixRebelOFFICER
2=5.0 upgradeKeyPrefixRebelOFFICER=4.0 upgradeKeyPrefixRebelORDNANCE
2=13.0 upgradeKeyPrefixRebelORDNANCE=12.0
upgradeKeyPrefixRebelSUPPORT TEAM=14.0 upgradeKeyPrefixRebelTITLE=3.0
upgradeKeyPrefixRebelTURBOLASER 2=16.0
upgradeKeyPrefixRebelTURBOLASER=15.0 upgradeKeyPrefixRebelWEAPONS
TEAM=17.0 upgradeRegex_DEFENSIVE 2=MC80\s+Assault
upgradeRegex_DEFENSIVE=Arquitens|ISD\s+(2|Kuat)|Assault\s+Frigate|CR90|MC30|MC75|MC80\s+(Assault|Command)
upgradeRegex_EXPERIMENTAL 2=Suppression
upgradeRegex_EXPERIMENTAL=Interdictor upgradeRegex_FLEET
COMMAND=Pelta|ISD\s+Cymoon upgradeRegex_FLEET SUPPORT=Gozanti|GR\-75
upgradeRegex_ION
CANNONS=CR90\-B|ISD\s+(2|Kuat|1)|Interdictor|MC75\s+Armored|MC80|Raider\s+2|Victory\s+2
upgradeRegex_OFFENSIVE 2=ISD\s+1|Quasar\s+Fire\s+1
upgradeRegex_OFFENSIVE=Gozanti|ISD|Interdictor|Quasar|Raider|Victory|Assault\s+Frigate|GR\-75|Hammerhead|MC75|MC80\s+Command|Pelta\s+Command
upgradeRegex_ORDNANCE 2=MC75\s+Ordnance
upgradeRegex_ORDNANCE=Hammerhead\s+Torpedo|Gladiator|ISD\s+Kuat|MC30|MC75|Raider\s+1|Victory\s+1|Pelta\s+Assault
upgradeRegex_SUPPORT
TEAM=Arquitens\s+CC|CR90|Gladiator|Interdictor|MC80|Pelta|Nebulon
upgradeRegex_TURBOLASER 2=ISD\s+Cymoon|MC80\s+(Star|Battle)
upgradeRegex_TURBOLASER=Arquitens|Assault\s+Frigate|CR90\-A|Hammerhead\s+Scout|ISD\s+(2|Cymoon|1)|MC30|MC75\s+Armored|MC80|Nebulon|Victory
upgradeRegex_WEAPONS TEAM 2=Quasar\s+Fire\s+2 upgradeRegex_WEAPONS
TEAM=Assault\s+Frigate|Hammerhead|Gladiator|ISD|MC30|MC75|MC80\s+(Battle|Star)|Quasar|Raider|Victory
For what it's worth, I'm experiencing much the same problem too. There's an older version of this Google Apps Script running and it's got around the same number of Properties. Going via the GAS interface I can't delete any of the properties. I've only just come across this problem so I haven't yet delved into a solution. The property I'm storing is a token for each user for a Service Account to utilise, so I'm hoping a programmatic purge of the tokens every x days will suffice. I'll post updates here.
In my case i couldn't save any file because an old linked library was deleted.

Google Maps API v3 Places Library returning undefined utc_offset

I'm developing a time and location aware application and the google maps v3 api places library has almost everything I need. However, when doing a textSearch() for specific addresses, and attempting to call getDetails() for one of the returned PlaceResult items, the PlaceResult.utc_offset property returned from getDetails() is undefined (all the other PlaceResult properties I need are returned fine, just not the utc_offset).
It's strange, because if I do a textSearch() for a generic term like "pizza" and then call getDetails() for one of the returned PlaceResult items, the PlaceResult.utc_offset property returned from getDetails() will have a value.
Does anyone know why the utc_offset is populated for the results of a generic search, but not when searching for a specific address, or what am I doing wrong?
As you mentioned in only works when there are generic terms like "pizza". What I've done is if it is undefined, I call the Google TimeZone API to get the info. I've put a code sample below, but you can see my solution on GitHub as well, https://github.com/pushpickup/pushpickup/blob/master/client/views/games/creategame/select-location.js#L13
if (place.utc_offset === void 0) {
timeStamp = (Date.now() || new Date().getTime())/1000;
timeZoneApiRequestUrl = "https://maps.googleapis.com/maps/api/timezone/json?location=" +
place.geometry.location.lat() + "," + place.geometry.location.lng() +
"&timestamp=" + timeStamp + "&key=YOUR_API_KEY"
$.get(timeZoneApiRequestUrl, function( data ) {
var utcOffset = (data.rawOffset + data.dstOffset || 0) / 3600;
console.log("UTC offset is " + utcOffset + " hours")
}); // expand this to handle errors, just doing a get with success for now as a POC
}

What is the maximum number of requests for Instagram?

I was wondering if there is a limitation of the number of images that are tagged that you can return?
This is my code:
<script type="text/javascript">
$(function() {
$.ajax({
type:'GET',
dataType:'jsonp',
cache: false,
url:'https://api.instagram.com/v1/tags/[TAG NAME]/media/recent?client_id=[CLIENT ID]',
success: function(data) {
for (var i = 0; i < 50; i++) {
$(".pics").append("<li><a target='_blank' href='" + data.data[i].link +
"' class='upshot-instagram' rel='instagram-group'><img src='" + data.data[i].images.thumbnail.url +"' ></img></a></li>");
}
}
});
});
</script>
I have 50 returning but I am only getting 20 images coming back to me. I know we have over 250 that have been tagged.
The API will only return 20 images per call. This is where the pagination data will come in handy, you can use the MAX_ID provided by the Instagram API, read more here.
This is in PHP and jQuery, but it can help you get on the right track: load more example
The default number of items returned is 20. However, you can specify more using a count parameter. At the time of this writing, it appears to be 33, but that could change as it is undocumented.
So the answer to your question is - 33, but it can (and probably will) change.
To answer your problem, you can use Instafetch, a script I wrote, which will paginate and filter for you, and allows you to fetch as many pictures as you specify.
In 2021, using the Instagram Basic Display API, the default number of media returned is 25. If the limit parameter is used, you exceed this default, but the maximum number of items returned is 100.
Here is an example cURL code snippet using the Me endpoint:
GET https://graph.instagram.com/me
?fields={fields}
&access_token={access-token}
&limit={required number of items}

AS3 / AIR readObject() from socket - How do you check all data has been received?

If you write a simple object to a socket:
var o:Object = new Object();
o.type = e.type;
o.params = e.params;
_socket.writeObject(o);
_socket.flush();
Then on the client do you simply use:
private function onData(e:ProgressEvent):void
{
var o:Object = _clientSocket.readObject();
}
Or do you have to implement some way of checking all of the data has been received recieved before calling .readObject()
There's 2 approaches:
If you're confident that your object will fit into one packet, you can do something like:
var fromServer:ByteArray = new ByteArray;
while( socket.bytesAvailable )
socket.readBytes( fromServer );
fromServer.position = 0;
var myObj:* = fromServer.readObject();
If you have the possibility of having multiple packet messages, then a common usage is to prepend the message with the length of the message. Something like (pseudo code):
var fromServer:ByteArray = new ByteArray();
var msgLen:int = 0;
while ( socket.bytesAvailable > 0 )
{
// if we don't have a message length, read it from the stream
if ( msgLen == 0 )
msgLen = socket.readInt();
// if our message is too big for one push
var toRead:int = ( msgLen > socket.bytesAvailable ) ? socket.bytesAvailable : msgLen;
msgLen -= toRead; // msgLen will now be 0 if it's a full message
// read the number of bytes that we want.
// fromServer.length will be 0 if it's a new message, or if we're adding more
// to a previous message, it'll be appended to the end
socket.readBytes( fromServer, fromServer.length, toRead );
// if we still have some message to come, just break
if ( msgLen != 0 )
break;
// it's a full message, create your object, then clear fromServer
}
Having your socket able to read like this will mean that multiple packet messages will be read properly as well as the fact that you won't miss any messages where 2 small messages are sent almost simultaneously (as the first message will treat it all as one message, thereby missing the second one)
Rule # 1 when dealing with TCP: it is an octet stream transfer protocol. You may never ever assume anything about how many octets (8 bit long values, commonly called bytes) you get in one go, always write code that can deal with any amount, both too few and too many. There is no gurantee that the write will not be split into multiple reads. There is also no gurantee that a single read will be from a single write.
The way I handled it was to make a call back that the server tell the client that the null bit was received.
The null bit is appended to the end of the data string you are sending to the server.
String.fromCharCode(0)
Also in your case you are doing
_socket.writeObject(o);
You should be sending a string not an object.
So Like this.
_socket.writeUTFBytes( 'Hellow World" + String.fromCharCode(0) );
NOTE *************
And one thing that most first time socket creators over look is the
fact that the first request to from the client to the server over the
port that the socket is connected on is a request for the
crossdomainpolicy.xml
If you only wish to send Objects, the simplest solution is if you send an int(size) before every object. Its not important to send the exact size, you can send a bit less. In my case, I've sent a bitmapdata, and the width and height of the object. obviously the bitmapdata's size is so big, its okay if you send only that, and ignore the rest.
var toRead=0;
protected function onSocketData(event:ProgressEvent):void{
if(toRead==0) {
toRead=socket.readInt()
}
if(socket.bytesAvailable>toRead){
var recieved:Object=socket.readObject()
/*do stuff with recieved object*/
toRead=0
}