0

Here is my code:

String key = Console.ReadLine();    //input oauth2.0 key from google
Console.WriteLine(key);
        Google.Apis.Admin.Directory.directory_v1.DirectoryService service = new Google.Apis.Admin.Directory.directory_v1.DirectoryService(new BaseClientService.Initializer
        {

        ApplicationName = "MY APPLICATION",
        ApiKey = key,


        });
Google.Apis.Admin.Directory.directory_v1.UsersResource.GetRequest u = service.Users.Get("test@example.net");
        Console.WriteLine(u.UserKey);


        Google.Apis.Admin.Directory.directory_v1.Data.User response = await u.ExecuteAsync();
Console.WriteLine(response);

Even though I have an OAuth2.0 key "key" from Google, I get an error message in reply saying something along the lines of error: login required. How should I change the code so that I can get (and eventually set) user information without such an error?

EDIT: My scope for the authorization key is the global user scope.

  • Are you passing oauth token in your request header? Issue should be with value of Authorization http header. check this link https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth – SGC Jun 08 '15 at 21:32

1 Answers1

1

I presume that you are using the Directory API ON Java. Follow this link, https://developers.google.com/admin-sdk/directory/v1/quickstart/java , it is the documentation of the Directory API of Google, and they have given the example for listing users.

Piyush Jain
  • 438
  • 4
  • 11