2017-03-17 46 views
0

我試圖使用OAuth 2.0無法更新密碼 - GoogleApiException - 無權訪問該資源

我遇到以下異常更新GSuite用戶密碼:

UpdateEmailUserPassword谷歌返回一個錯誤反對這種用戶。請查看谷歌異常的詳細信息,並確保這是一個有效的現有用戶

UpdateEmailUserPassword谷歌異常詳細信息:服務管理員已拋出異常:Google.GoogleApiException:Google.Apis.Requests.RequestError 無權訪問該資源/ api [403] 錯誤[信息[未經授權訪問此資源/ api]位置[ - ]原因[禁止]域[全局]

我可以確認使用的管理員帳戶是所有API的超級管理員帳戶適用於ClientID和服務帳戶的範圍。我錯過了什麼嗎?

回答

0

根據此thread,您需要創建一個service object授權的服務帳戶,該帳戶將代表給定用戶。嘗試將用戶成員添加到ServiceAccountCredential.Initializer

樣品:

ServiceAccountCredential credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail) 

    { 
    Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser }, 
    User = "[email protected]" <-------- Added ADMIN User to fix 
    }.FromCertificate(certificate));