![]() |
VOOZH | about |
The CData Cmdlets for Instagram are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Instagram.
The Cmdlets are not only a PowerShell interface to Instagram, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Instagram data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Instagram. To access Instagram data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Instagram.
Once you have acquired the necessary connection properties, accessing Instagram data in PowerShell can be enabled in three steps.
Instagram uses the OAuth 2 authentication standard. Obtain the OAuthClientId, OAuthClientSecret, and CallbackURL by registering an app with Instagram. See the help documentation for a guide.
Install the module:
Install-Module InstagramCmdlets
Connect:
$instagram = Connect-Instagram -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$tagname = "goldfish" $media = Select-Instagram -Connection $instagram -Table "Media" -Where "TagName = `'$TagName`'" $media
You can also use the Invoke-Instagram cmdlet to execute SQL commands:
$media = Invoke-Instagram -Connection $instagram -Query 'SELECT * FROM Media WHERE TagName = @TagName' -Params @{'@TagName'='goldfish'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Instagram\lib\System.Data.CData.Instagram.dll")
Connect to Instagram:
$conn= New-Object System.Data.CData.Instagram.InstagramConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the InstagramDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Link, LikesCount from Media"
$da= New-Object System.Data.CData.Instagram.InstagramDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.link $_.likescount
}
Update-Instagram -Connection $Instagram -Columns @('Link','LikesCount') -Values @('MyLink', 'MyLikesCount') -Table Media -Id "MyId"
$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("UPDATE Media SET TagName='goldfish' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Instagram -Connection $Instagram -Table Media -Columns @("Link", "LikesCount") -Values @("MyLink", "MyLikesCount")
$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("INSERT INTO Media (TagName) VALUES (@myTagName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myTagName","goldfish")))
$cmd.ExecuteNonQuery()
Remove-Instagram -Connection $Instagram -Table "Media" -Id "MyId"
$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("DELETE FROM Media WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Instagram Data Provider to get started:
Download NowLearn more:
👁 Instagram IconA straightforward interface to connect any .NET application with Instagram integration capabilities including Users, Relationships, Media, Tags and more!