Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

javascript - Error coming while fetch items from multiple Instagram accounts

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...