2016-04-28 59 views
0

我想访问Dropbox指标,类似于Dropbox管理控制台上提供的指标,例如存储信息和共享文件夹数。 Dropbox API提供了丰富的大量信息,因此我如何通过Powershell获得这些信息?通过Powershell访问Dropbox指标

回答

0

该API将提供许多关于指标的信息。下面的例子使用1.0 API,很快将被2.0版所取代。有关API的文档,请转到Dropbox.com/developer

本示例生成最新的存储和共享文件夹度量标准。

示例输出:

2016年4月27日00:00:00,6220390,2163

# Prompt or hard-code for Team Member Management permission 
# the Token is obtained from Dropbox website - the Admin Console 
#$token = Read-Host -Prompt "Enter your Dropbox Business API App token (Team Member Management permission): " 
$token = "Bearer KXasdflkjasfoivXnasdliefdslksafToivU932432489432" 

$object = New-Object psobject 

# Make API call 
$teamstats = Invoke-RestMethod -Uri https://api.dropbox.com/1/team/reports/get_storage -Body (ConvertTo-Json $object) -ContentType application/json -Headers @{ 
      Authorization = $token } -Method Post 

# API returns 1 startdate only, which is the day before the data actually begins 
$startdate = [datetime]$teamstats.start_date 

#API returns in an array various elements such as storage consumed & number of shared folders 
#below I convert them to an array with a simpler name 
$StorageArray = $teamstats.total_usage 
$ShareArray = $teamstats.shared_folders 

# of entries in the array 
$MaxCount = $storagearray.length 

# I am only interested in the last entry (most current) 
$LastEntry = $MaxCount - 1 

#adjust the date so it reflects the right time period 
$ts = New-TimeSpan -Days $lastentry 
$startdate = $startdate + $ts 

#grab the last entry for storage and shares 
$storage = $StorageArray[$LastEntry] 
$Shares = $ShareArray[$LastEntry] 

#I load this data into other software, which cannot deal with storage in Bytes 
#when the number is so large (terabytes) 
#so I convert it to megabytes 
[long]$intNum = $Storage -as [long] 
$intnum = $intnum/(1024 * 1024) # convert to mb 

"$startdate,$intnum,$Shares" 

Write-Host "Press any key to continue ..." 

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")