助けを求めています。私はすべてのドキュメント、SO、Google を調べましたが、まだ運がありません。
「空き状況の確認」機能のために、Web アプリケーションで Google Calendar API と統合しようとしています。現在、私はフックインの非常に基本的な段階にあり、私が得た最も遠いものは、認証してデータを引き出そうとしているだけです. 以下に私のコードを含めました -私が見たすべてのアドバイスに従った後、私が得ているのは403 Forbiddenエラーだけです.
誰かが私が間違っている場所を見つけることができますか?
public void Page_Load(object sender, EventArgs e)
{
// 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 = "MY_CLIENT_ID";
provider.ClientSecret = "MY_SECRET";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer
{
Authenticator = auth
});
EventsResource.ListRequest req = service.Events.List("primary");
if (req != null)
{
var events = req.Fetch();
if (events != null)
{
litResult.Text = events.Items.Count().ToString();
}
else
{
litResult.Text = "Zilch.";
}
}
else
{
litResult.Text = "Nada.";
}
}
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { "https://www.google.com/calendar/feeds" });
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);
}