我正在使用Google Calendar Api
我的一个项目。我不知道如何,但下面的错误令人不安。
AppFlowMetadata
内的代码。
public class AppFlowMetadata : FlowMetadata
{
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
ClientSecret = "xxxxx_xxxxxxxxxxxxxxxxx"
},
Scopes = new[] { CalendarService.Scope.Calendar },
DataStore = new FileDataStore("Calendar.Api.Auth.Store")
});
public override string GetUserId(Controller controller)
{
var user = controller.Session["UserID"];
if (user == null)
{
user = Guid.NewGuid();
controller.Session["UserID"] = user;
}
return user.ToString();
}
public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}
我在下面尝试了GitHub的解决方案但是没有工作
以上解决方案对我没有用,如果有任何答案请帮忙。
答案 0 :(得分:4)
根据https://domantasjovaisas.wordpress.com/2014/09/27/demystifying-google-api-and-oauth2/:
从我刚提供的代码中你可以看到我正在使用File2DataStore。 它被我超越了。标准FileDataStore我改为自己的 需要。标准FileDataStore存储身份验证密钥 “C:\ Windows \ system32 \设置\ systemprofile \应用程序数据\漫游\ Drive.Api.Auth.Store”
我不认为你会允许IIS_IUSRS用户访问它 在生产环境中的位置三思而后行,不要那样做。 根据您自己的需要重写FileDataSource。以下是您的两个例子 可以做到:
https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs http://www.daimto.com/google-oauth2-csharp/#FileDataStore
简而言之,您需要停止使用FileDataStore
并编写自己的替代品(使用上述链接作为起点)。
答案 1 :(得分:2)
问题是默认情况下
new FileDataStore("Calendar.Api.Auth.Store")
将数据存储在需要特殊权限的路径中,因此将完整路径作为参数发送。
而不是
new FileDataStore("Calendar.Api.Auth.Store")
将完整路径发送到要保存在文件系统中的位置,将第二个参数设置为true,例如
new FileDataStore(fullpath, true);
那应该有用。 祝你好运
答案 2 :(得分:1)
我认为您没有授予此文件夹 C:\Windows\system32\config\systemprofile
的权限。尝试使用像此图像这样的绝对路径或将相对路径转换为绝对路径(通过使用服务器地图路径)。
确保您对此文件夹有足够的权限。
答案 3 :(得分:-2)
我不知道谷歌API ...但该文件夹具有特定的安全性,只允许Administrators
组成员访问。
也许用户(由IIS或Visual Studio使用)必须是本地计算机Administrator
组(\ Administrator)的成员。
顺便说一句,在Visual Studio中,您必须以管理员身份启动。