C# で google-admin-sdk を使用する方法のコツをつかもうとしています (求人の可能性があります)
コマンドライン ツールとして Python 2.7 でユーザーを作成し、ユーザーをグループに追加するためのコードを作成することができました。
しかし、雇用主は med に、C# で同じことができるかどうか尋ねました。コツはつかめると思いますが、始め方のアドバイスをいただければ幸いです。デスクトップ用の Visual Studio Express 2012 をインストールしてダウンロードしました: google-admin-directory_v1-rev6-csharpp-1.4.0-beta.zip google-api-dotnet-client-1.4.0-beta-samples.zip dotnet-client-1.4.0-beta.zip
しかし、(私にとっては理解できる)サンプルが見つかりません。
良い指針を教えてくれる人はいますか?大変感謝しております。:) /ジョナス
編集:これまでにコードを追加してください!
using System;
using System.Diagnostics;
using System.Linq;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Samples.Helper;
using Google.Apis.Services;
using Google.Apis.Util;
using Google.Apis.Admin.directory_v1;
using Google.Apis.Admin.directory_v1.Data;
namespace Bergstedts.ListUsers
{
public class Program
{
static void Main(string[] args)
{
// Display the header and initialize the sample.
CommandLine.EnableExceptionHandling();
CommandLine.DisplayGoogleSampleHeader("Lists all Users");
// Register the authenticator.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = "my ID",
ClientSecret = "my secret"
};
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
// Create the service.
var service = new DirectoryService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = "List Users",
});
service.Users.List().Domain = "mydomain.com";
Users results = service.Users.List().Execute();
Console.WriteLine("Users:");
foreach (User list in results.UsersValue)
{
Console.WriteLine("- " + list.Name);
}
Console.ReadKey();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { DirectoryService.Scopes.AdminDirectoryUser.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);
}
}
}
編集:ドメインを追加する方法を見つけました:
service.Users.List().Domain = "mydomain.com";
しかし、私はまだ同じエラーメッセージを受け取ります: エラーが発生しました: Google.Apis.Requests.RequestError Bad Request [400] Errors [ Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global] ]