Esempio n. 1
0
        public static Person getPlusUser(PlusService serviceplus)
        {
            PeopleResource.GetRequest personRequest = serviceplus.People.Get("me");
            Person user = personRequest.Execute();

            return(user);
        }
Esempio n. 2
0
        public string GetId(string gmail)
        {
            var decId = RegisterUser(gmail);

            var contactInfoResponse = GetAddInfo();

            if (contactInfoResponse.Exception == null)
            {
                var person = contactInfoResponse.Result.Connections.Where(x => x.ResourceName.Contains(decId.Result)).ToList();

                if (person.Any())
                {
                    return(person.First().CoverPhotos[0].Metadata.Source.Id);

                    //var result = typeof(Person).GetProperties()
                    //.Select(x => new { property = x.Name, value = x.GetValue(person[0]) })
                    //.Where(x => x.value != null)
                    //.ToList();

                    // photo: property photos [0]

                    //System.IO.File.WriteAllText(@"C:\\Users\\me\\Desktop\\result.json", JsonConvert.SerializeObject(result));
                }
            }
            else
            {
                var request = new PeopleResource.GetRequest(peopleService, decId.Result);
                request.PersonFields = "metadata";

                var requestResult = request.Execute();

                if (requestResult.Metadata.Sources.Count > 1)
                {
                    return(requestResult.Metadata.Sources[1].Id);
                }
            }

            DeleteUser(decId.Result);


            return(String.Empty);
        }
Esempio n. 3
0
        public async static Task <Person> GetPeopleInfo(UserCredential credential, string userid)
        {
            //directory api key AIzaSyBq6xSct8OhL2-5zUWMH73wRIN6iFGOg2k
            //people und cloud resource manager api key AIzaSyBtsaZHK0PswRKIcErSX7eH7ojT_rHeKpE
            var service = new PeopleService(new BaseClientService.Initializer
            {
                //HttpClientInitializer = credential,
                ApiKey          = "AIzaSyBtsaZHK0PswRKIcErSX7eH7ojT_rHeKpE",
                ApplicationName = "UbiGrade"
            });

            PeopleResource.GetRequest request = service.People.Get("people/me");
            request.BearerToken             = credential.Token.AccessToken;
            request.RequestMaskIncludeField = "people.names";

            // htl orgunit id = 1056718226129

            var x = await request.ExecuteAsync();

            return(x);
        }
Esempio n. 4
0
        public async Task Login()
        {
            if (isAlreadyInLoginProcess || credential != null)
            {
                CancelLogin();
            }
            else
            {
                isAlreadyInLoginProcess = true;
                source = new CancellationTokenSource(new TimeSpan(0, 1, 0));
                token  = source.Token;

                FileStream stream   = new FileStream(System.Windows.Forms.Application.StartupPath + "credentials.json", FileMode.Open, FileAccess.Read);
                string     credPath = "token.json";
                await Task.Run(() =>
                {
                    try
                    {
                        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                            GoogleClientSecrets.Load(stream).Secrets,
                            scopes,
                            "NotesieveDesktopUser",
                            token,
                            new FileDataStore(credPath, true)).Result;
                    }
                    catch (System.AggregateException e)
                    {
                        if (token.IsCancellationRequested)
                        {
                            //Операция прервана
                        }
                        else
                        {
                            OnError?.Invoke(e.InnerException + " " + e.Message);
                        }
                        isAlreadyInLoginProcess = false;
                    }
                    catch (System.Net.Http.HttpRequestException e)
                    {
                        isAlreadyInLoginProcess = false;
                        OnSyncStateChanged?.Invoke(gSyncState.eFailed);
                        OnError?.Invoke("Проблема с интрнєт-соединением.\nВы можете продолжать использовать Notesieve но временно, не сможете его синхронизировать.");
                    }
                });

                if (credential == null)
                {
                    isAlreadyInLoginProcess = false;
                    OnLoginFailed?.Invoke();
                }
                else
                {
                    try
                    {
                        isAlreadyInLoginProcess = false;
                        PeopleServiceService peopleService = new PeopleServiceService(new BaseClientService.Initializer()
                        {
                            HttpClientInitializer = credential,
                            ApplicationName       = applicationName,
                        });
                        isLogin = true;
                        PeopleResource.GetRequest peopleRequest = peopleService.People.Get("people/me");
                        peopleRequest.PersonFields = "names,photos";
                        Person profile = peopleRequest.Execute();
                        string name    = profile.Names[0].DisplayName;
                        string photo   = profile.Photos[0].Url;
                        OnLoginSuccsesfull?.Invoke(name, photo);
                    }
                    catch (System.Net.Http.HttpRequestException e)
                    {
                        isAlreadyInLoginProcess = false;
                        OnSyncStateChanged?.Invoke(gSyncState.eLostConnection);
                        OnError?.Invoke("Проблема с интрнєт-соединением.\nВы можете продолжать использовать Notesieve но временно, не сможете его синхронизировать.");
                    }
                }
            }
        }
 /// <summary>
 /// Get a person
 /// Documentation: https://developers.google.com/+/api/latest/people/get
 /// </summary>
 /// <param name="service"></param>
 /// <param name="_userId">Get a person's profile.If using the userId value "me", this method requires authentication using a token that has been granted the OAuth scope</param>
 /// <returns></returns>
 public static Person GetPerson(PlusService service, string _userId)
 {
     PeopleResource.GetRequest personRequest = service.People.Get(_userId);
     return personRequest.Execute();
 }