Google API .Net客户端库身份验证错误

时间:2016-04-19 09:33:03

标签: authorization google-api-dotnet-client

按照此处的指南:.NET Quickstart我能够从客户端执行示例脚本。但是,当我添加电子表格功能时,我必须包含一个额外的范围。当我这样做时,身份验证页面给了我一个错误:

  

“400。这是一个错误。错误:invalid_request redirect_url的参数值无效”

检查url后,似乎url参数被编码两次,除了范围之间的空间,而不是只有一次我只请求一个范围:

  

https://accounts.google.com/o/oauth2/auth?access_type=offline&response_type=code&client_id=637584198824-siuv8qtmjvqokpnipc5oibr57s8a4jj2.apps.googleusercontent.com&redirect_uri=http:%252F%252Flocalhost:52178%252Fauthorize%252F&scope=https:%252F%252Fwww.googleapis.com%252Fauth%252Fspreadsheets%20https:%252F%252Fwww.googleapis.com%252Fauth%252Fdrive

这是我的范围数组:

static readonly string[] s_scopesExecution = {
    "https://www.googleapis.com/auth/spreadsheets",
    "https://www.googleapis.com/auth/drive",
};

我传递给我的授权码

using (var stream = new FileStream(CLIENT_SECRET_FILEPATH, FileMode.Open, FileAccess.Read))
{
    string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    credPath = Path.Combine(credPath, CRED_BASE_PATH);

    //determine scopes
    string[] scopes = s_scopesExecution;

    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        scopes,
        userName,
        CancellationToken.None,
        new FileDataStore(credPath, true)).Result;

}

当我将两个范围放在由空格分隔的一个字符串中时,会发生同样的错误。

这是客户端库的错误还是我做错了什么?

0 个答案:

没有答案