Automate Instagram Integration Tasks from PowerShell
The CData ADO.NET Provider for Instagram is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Instagram.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Instagram; this tutorial shows how to use the Provider to create, retrieve, update, and delete Instagram data.
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.
-
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 Data
$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()
Insert Instagram Data
$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()
Delete Instagram Data
$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