My Script
function Get-InstagramData() {
$accounts = @("capitals", "monumental_sports", "washwizards", "washmystics")
$accounts | ForEach-Object {
$url = "https://www.instagram.com/$_"
$source = $_
$response = Invoke-WebRequest -Uri $url -Method Get
#$response.Content -match '<script type="text/javascript">window._sharedData = ([^;]*)'
$response.Content -match '<script type="text/javascript">window._sharedData = ([^>]*)'
$value = $Matches[0] -replace '<script type="text/javascript">window._sharedData = ', ''
$value= $value -replace ';</script',''
$json = $value | ConvertFrom-Json
$cnt=0;
$json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges | ForEach-Object {
if($cnt -lt 10)
{
$shortCode = $_.node.shortcode
$thumbnaailSrc = $_.node.thumbnail_src
$accessibilityCaption = $_.node.accessibility_caption
$takenTimestamp = $_.node.taken_at_timestamp
$captiontext = $_.node.edge_media_to_caption.edges[0].node.text
# Write information to SP - up to 10 latest post from each account
Set-PostInSharePoint -shortCode $shortCode -thumbnail $thumbnaailSrc -source $source -caption $accessibilityCaption -timestamp $takenTimestamp -imgcaption $captiontext
}
$cnt++;
}
}
}
Error:
Cannot index into a null array.
At line:15 char:9
+ $json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_m
...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…