Hello,

With powershell I connect to Google with oauth. The setup all works, but 
when i want to get some data back I get an 401 error.
Here is the error and the powershell script that I have so far. Does anyone 
knowns how to get data  ? I want to retrieve Photo information.

Invoke-RestMethod: {
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. 
Expected OAuth 2 access token, login cookie or other valid authentication 
credential. See 
https://developers.google.com/identity/sign-in/web/devconsole-project.";,
    "status": "UNAUTHENTICATED"
  }
}

-------------- POWERSHELL SCRIPT ----------------

#-----------------------------------------------------------[variable]------------------------------------------------------------
$clientid = "*******************.apps.googleusercontent.com"
$clientsecret = "***************"
$baseurl = "https://photoslibrary.googleapis.com";
$redirectURI = "urn:ietf:wg:oauth:2.0:oob"
$scopes = 
"https://www.googleapis.com/auth/photoslibrary","https://www.googleapis.com/auth/photoslibrary.readonly","https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata";

#-------------------------------------------------------[get 
permissions]---------------------------------------------------------
Start-Process 
"https://accounts.google.com/o/oauth2/v2/auth?client_id=$clientId&scope=$([string]::Join("%20",
 
$scopes))&access_type=offline&response_type=code&redirect_uri=$redirectURI"
$code = Read-Host "Please enter the code"
$body=@{}
$body = @{
    client_id=$clientid
    client_secret=$clientSecret
    redirect_uri=$redirectURI
    code=$code
    grant_type="authorization_code"
}
$response = invoke-restmethod https://www.googleapis.com/oauth2/v4/token 
-Method POST -Body $body
$access_token = $response.access_token

#-----------------------------------------------------------[execution]------------------------------------------------------------
$header = @{}
$header["authorization"] = "bearer $($access_token)"
$header["content-type"] = "application/json"

$url = "$baseurl/v1/albums"
# this part gives an error
$webreq = Invoke-RestMethod $url -headers $header -method get -body 
$content -ContentType "application/json"

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/64d8a3c7-9d7c-46de-a118-54b07c626d7an%40googlegroups.com.

Reply via email to