【发布时间】:2020-11-01 09:42:39
【问题描述】:
我使用的是 GoogleWebAuthorizationBroker,但发布后它不起作用,我更改为 GoogleAuthorizationCodeFlow 但我得到空令牌响应
public static Google.Apis.Drive.v3.DriveService GetService()
{
var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "-----",
ClientSecret = "----"
},
Scopes = new[] { Google.Apis.Drive.v3.DriveService.Scope.DriveReadonly, "email" },
DataStore = new FileDataStore(Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("/"), "DriveServiceCredentials.json"), true)
});
TokenResponse token = flow.LoadTokenAsync("user", CancellationToken.None).Result;
UserCredential credential = new UserCredential(flow, "user", token);
Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GoogleDriveRestAPI-v3",
});
return service;
}
【问题讨论】:
-
任何解决方案......?
-
您的
credentials.json文件是否位于要访问的正确目录中?你有生成的token文件吗?如果可以,请您将其删除以查看是否可以成功生成新令牌?你关注this guide授权了吗? -
是的,我在正确的目录中有 credentials.json 文件
-
我更新代码
标签: asp.net-mvc google-api google-drive-api google-oauth