首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google.GoogleApiException时“Google.Apis.Requests.RequestError请求缺少必需的身份验证证书”

使用Google.GoogleApiException时“Google.Apis.Requests.RequestError请求缺少必需的身份验证证书”
EN

Stack Overflow用户
提问于 2018-03-15 06:58:28
回答 1查看 3.6K关注 0票数 3

使用.net,我试图向Google ScriptService发出请求,但是我一直收到这个错误:“请求缺少所需的身份验证证书”,尽管我包括了凭证。事实上,在不久之前,我使用相同的凭据成功地向YoutubeService提出了请求。

下面是我的代码,它实际上是用来工作的,所以我不确定是什么改变了:

代码语言:javascript
复制
Scopes = new string[] { ScriptService.Scope.Forms, ScriptService.Scope.Spreadsheets,
            ScriptService.Scope.Drive, YouTubeService.Scope.YoutubeUpload, YouTubeService.Scope.Youtube };

UserCredential credential;
using (var stream = new FileStream(@"Resources\client_secret.json", FileMode.Open, FileAccess.Read))
{
    var credPath = Path.Combine(parentDir, ".credentials/" + folderName);

    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
         GoogleClientSecrets.Load(stream).Secrets,
         Scopes,
         "user",
         CancellationToken.None,
         new FileDataStore(credPath, true)).Result;
}

// Create Google Apps Script Execution API service.
var service = new ScriptService(new BaseClientService.Initializer()
{
    HttpClientInitializer = this.credential,
    ApplicationName = Properties.Resources.ApplicationName,
 });

// Create an execution request object.
ExecutionRequest request = new ExecutionRequest();
request.Function = "createForm";
request.Parameters = new List<object>();
request.Parameters.Add(this.id);
request.Parameters.Add(name);
request.Parameters.Add(email);
request.Parameters.Add(this.link);

ScriptsResource.RunRequest runReq = service.Scripts.Run(request, Globals.Script_ID);

try
{
    // Make the API request.
    Operation op = runReq.Execute();
catch (Google.GoogleApiException e)
{
    Debug.WriteLine("Error calling API:\n{0}", e.ToString());
}

我在开发人员控制台中启用了API并为我的平台生成了OAuth 2.0凭据。client_secret.json是我从控制台下载的OAuth 2.0凭据。

对可能出什么问题有什么想法吗?我记得在更新我的google包后有一个类似的问题,但是在这个例子中,我没有这样做。我还试着更新包,但还是遇到了同样的问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-16 03:04:01

问题是我没有正确的授权范围。最初我有:

代码语言:javascript
复制
Scopes = new string[] { ScriptService.Scope.Forms, ScriptService.Scope.Spreadsheets,
        ScriptService.Scope.Drive, YouTubeService.Scope.YoutubeUpload, YouTubeService.Scope.Youtube };

然而,在检查我的应用程序脚本Properties中的"Scopes“选项卡时,我忽略了"userinfo.email”范围。因此,我以以下方式更新了代码:

代码语言:javascript
复制
Scopes = new string[] { ScriptService.Scope.Forms, ScriptService.Scope.Spreadsheets,
        ScriptService.Scope.Drive, ScriptService.Scope.UserinfoEmail, YouTubeService.Scope.YoutubeUpload, YouTubeService.Scope.Youtube };

我的猜测是,自几个月前我最初编写脚本以来,API就已经被更新了,因为我当时能够用我拥有的三个原始授权成功地运行它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49293282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档