谷歌身份验证过程 [英] Google Authentication Process
问题描述
我想写一本机应用程序访问用户的谷歌日历。我想用这个例子,谷歌提供了得到验证,但它似乎永远不会触发验证功能
I am trying to write a native app to access a users google calendar. I am trying to use the example that google has provided to get authentication but it never seems to fire the authentication function
private void Window_Initialized(object sender, EventArgs e)
{
var provider = new NativeApplicationClient(
GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "<My Client Id here>";
provider.ClientSecret = "<My Client Secret here";
var auth = new OAuth2Authenticator<NativeApplicationClient>(
provider, (p) => GetAuthorization(provider));
CalendarService service = new CalendarService();
CalendarsResource.GetRequest cr = service.Calendars.Get("{primary}");
if (cr.CalendarId != null)
{
Console.WriteLine("Fetching calendar");
//Google.Apis.Calendar.v3.Data.Calendar c =
service.Calendars.Get("{primary}").Fetch();
}
else
{
Console.WriteLine("Service not found");
}
}
下面是我使用验证码。我从来没有看到的WriteLine得到出版控制台。
Here is the code that I am using for Authentication. I never see the console writeline get published.
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
Console.WriteLine("Authorization Requested");
IAuthorizationState state = new AuthorizationState(
new[] { CalendarService.Scopes.Calendar.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
Process.Start(authUri.ToString());
// Request authorization from the user and get the code
string authCode = Console.ReadLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
还有没有更好的教程可用的还是我做错了什么?
Are there any better tutorials available or am I doing something wrong?
推荐答案
该示例代码被打破了。为了使该服务使用您的认证,您需要连接它。在这个例子中有服务和鉴别码之间没有关联。创建这样的服务:
The example code is broken. To make the service use your authenticator, you need to connect it. In the example there is no association between the service and the authenticator. Create the service like this:
var service = new CalendarService(new BaseClientService.Initializer()
{
Authenticator = auth
};
看的 https://code.google.com/p/google-api-dotnet-client/ 以更好的文档/工作代码。
Look at https://code.google.com/p/google-api-dotnet-client/ for better documentation/working code.
这篇关于谷歌身份验证过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!