![](/img/trans.png)
[英]Changing Title of Google Calendar event using Google Calendar API v3 and Data Repeater
[英]Creating Event in Google calendar using api v3
我已經在c#.net中嘗試了來自Google的此示例,但是它不適用於我。 任何人都有Google日歷api v3的任何示例
它向我顯示錯誤,因為AuthenticatorFactory當前內容中不存在。
我用谷歌給的dll
using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Util;
namespace Sample.Console
{
class Program
{
static void Main(string[] args)
{
// Register the authenticator. The Client ID and secret have to be copied from the API Access
// tab on the Google APIs Console.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "YOUR_CLIENT_ID";
provider.ClientSecret = "YOUR_CLIENT_SECRET";
AuthenticatorFactory.GetInstance().RegisterAuthenticator(
() => new OAuth2Authenticator(provider, GetAuthentication));
// Create the service. This will automatically call the previously registered authenticator.
var service = new CalendarService();
}
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
谷歌沒有使用Auth Factory使用OAuth2身份驗證器對象,而是沒有很好地記錄此更改...僅使用AuthenticatorFactory.GetInstance()刪除了代碼,然后用此行代碼替換。 其他一切都應該保持不變。
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.