Hi all,
I'm trying to get an OpenAuth2 access token in order to ultimately extract data from Google Analytics.
I can create a code url and pass that to the chrome browser and the request is serviced displaying the access code in the URL bar. I cannot however seem to grab this code using powershell as there is no ComObject for Chrome (as far as i can tell).
I've tried this using IE (which i can grab the URL using the ComObject) however the request doesn't seem to be serviced in IE and instead i get "This page can't be displayed" (the access code is not displayed in the URL string as it is with Chrome)
Is there some setting i am missing in IE?
<code>
#Declarations$clientId = "**"
$clientSecret = "**"
#return to us locally
$redirectUri = "http://localhost:8080/"
$email = "**"
$passwd = "**"
$grantType = "authorization_code"
$scope= "https://www.googleapis.com/auth/analytics"
$responseType = "code"
$getCodeUrl = "https://accounts.google.com/o/oauth2/auth?scope=$scope&redirect_uri=$redirectUri&response_type=$responseType&client_id=$clientId"
#Auto Sign in to Google accounts
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true
$ie.navigate('http://www.gmail.com')
while($ie.Busy)
{
sleep -mil 100
}
if($ie.Document.Url -match 'Inbox')
{
Write-Host 'Account already logged in'
#return $ie
}
else
{
$ie.Document.getElementById("email").value=$email
$ie.Document.getElementByID("Passwd").value=$passwd
$ie.Document.getElementById("signin").Click()
while($ie.Busy)
{
sleep -mil 100
}
if($ie.Document.Url -match 'Inbox')
{
Write-Host 'Successfull login!'
#return $ie
}
else
{
Write-Host 'Login failed!'
}
}
#IE doesn't appear to return the access code like Chrome
$ie.navigate($getCodeUrl)
</code>