Exemplo n.º 1
0
        Button CreateApiButton(AuthenticatedApi api)
        {
            var button = new Button
            {
                Text = $"Login: {api.GetType().Name}",
            };

            button.Clicked += async(sender, args) =>
            {
                try
                {
                    _sourceApi = api;
                    var account = await api.Authenticate() as OAuthAccount;

                    Console.WriteLine(account.Identifier + " : " + account.Token);
                    await MainPage.DisplayAlert("Success!", "User is logged in", "Ok");
                } catch (TaskCanceledException) {
                    Console.WriteLine("Canceled");
                    await MainPage.DisplayAlert("Error", "User Canceled", "Ok");
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                    await MainPage.DisplayAlert("Error", ex.Message, "Ok");
                }
            };
            return(button);
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            this.authenticatedApi = AuthenticatedApi.Merge(Api.Default, "dummy", "dummyToken");
            this.preparer         = new RemoteSourcePreparer(this.authenticatedApi);
            this.settings         = new AnalysisSettings();

            this.audioRecording = AudioRecordingFactory.Create();
            this.audioRecording.DurationSeconds = 240.113;
        }
Exemplo n.º 3
0
        public App()
        {
            var scopes = new[]
            {
                "https://www.googleapis.com/auth/userinfo.email",
                "https://www.googleapis.com/auth/userinfo.profile"
            };

            //api = new GoogleApi("google",
            //	   "clientid",
            //	"clientsecret",new ModernHttpClient.NativeMessageHandler())
            //{
            //	Scopes = scopes,
            //};

            api = new FacebookApi("facebook", "", "");

            var button = new Button
            {
                Text = "Login",
            };

            button.Clicked += async(sender, args) =>
            {
                try
                {
                    var account = await api.Authenticate();

                    var me = await api.Get("me");

                    Console.WriteLine(account.Identifier);
                }
                catch (TaskCanceledException)
                {
                    Console.WriteLine("Canceled");
                }
            };
            // The root page of your application
            MainPage = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        button
                    }
                }
            };
        }
Exemplo n.º 4
0
        Button CreateApiButton(AuthenticatedApi api)
        {
            var button = new Button
            {
                Text = $"Login: {api.GetType().Name}",
            };

            button.Clicked += async(sender, args) =>
            {
                try
                {
                    var account = await api.Authenticate();

                    Console.WriteLine(account.Identifier);
                }
                catch (TaskCanceledException)
                {
                    Console.WriteLine("Canceled");
                }
            };
            return(button);
        }
Exemplo n.º 5
0
        Button CreateApiButton(AuthenticatedApi api)
        {
            var button = new Button
            {
                Text = $"Login: {api.GetType().Name}",
            };
            button.Clicked += async (sender, args) =>
            {
                try
                {
                    var account = await api.Authenticate();
                    var me = await api.Get("me");

                    Console.WriteLine(account.Identifier);
                }
                catch (TaskCanceledException)
                {
                    Console.WriteLine("Canceled");
                }
            };
            return button;

        }
Exemplo n.º 6
0
        public App()
        {
            //Hook up our Forms login page for Basic Auth
            BasicAuthApi.ShowAuthenticator = (BasicAuthAuthenticator obj) => {
                MainPage.Navigation.PushModalAsync(new LoginPage(obj));
            };

            var scopes = new[]
            {
                "https://www.googleapis.com/auth/userinfo.email",
                "https://www.googleapis.com/auth/userinfo.profile"
            };

            //api = new GoogleApi("google",
            //	   "clientid",
            //	"clientsecret",new ModernHttpClient.NativeMessageHandler())
            //{
            //	Scopes = scopes,
            //};

            //api = new FacebookApi("facebook","","");
            api = new OAuthPasswordApi("myapi", "clientid", "clientsecret",
                                       "https://serverurl.com",
                                       "https://tokenurl.com",
                                       "https://refreshurl.com")
            {
                //Hook up our Forms login page for Oauth with Password
                CurrentShowAuthenticator = (obj) => {
                    MainPage.Navigation.PushModalAsync(new LoginPage(obj));
                },
            };

            var button = new Button
            {
                Text = "Login",
            };

            button.Clicked += async(sender, args) =>
            {
                try
                {
                    var account = await api.Authenticate();

                    var me = await api.Get("me");

                    Console.WriteLine(account.Identifier);
                }
                catch (TaskCanceledException)
                {
                    Console.WriteLine("Canceled");
                }
            };
            // The root page of your application
            MainPage = new NavigationPage(new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        button
                    }
                }
            });
        }
Exemplo n.º 7
0
        public App()
        {
            //Hook up our Forms login page for Basic Auth
            BasicAuthApi.ShowAuthenticator = (IBasicAuthenicator obj) => {
                MainPage.Navigation.PushModalAsync(new LoginPage(obj));
            };

            string FacebookClientId = "528997441203195";
            string FacebookSecret   = "db801dd6f6bc40702ebbd70ecdef4d4e";

            string InstagramClientId = "f2c421d810824581ac758861e56e5340";
            string InstagramSecret   = "2465b93d4cc44355a4ccf32f3eca707a";

#if __ANDROID__
            string GoogleClientId = "646679266669-quj4b4frm8gi4knn6269me7ss9cefj7c.apps.googleusercontent.com";
            string GoogleSecret   = GoogleApi.NativeClientSecret;           //"uzj06SA8A66Y9mOA1rSjmQH7";
#else
            string GoogleClientId = "992461286651-k3tsbcreniknqptanrugsetiimt0lkvo.apps.googleusercontent.com";
            string GoogleSecret   = "avrYAIxweNZwcHpsBlIzTp04";
#endif

            var logoutButton = new Button()
            {
                Text = "Logout"
            };
            logoutButton.Clicked += async(sender, args) =>
            {
                if (_sourceApi != null)
                {
                    _sourceApi.Logout();
                    _sourceApi = null;
                }
            };


            // The root page of your application
            MainPage = new NavigationPage(new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        CreateApiButton(new GoogleApi("google",                          GoogleClientId,    GoogleSecret)
                        {
                            Scopes = new[]
                            {
                                "https://www.googleapis.com/auth/userinfo.email",
                                "https://www.googleapis.com/auth/userinfo.profile"
                            },
                        }),
                        CreateApiButton(new FacebookApi("facebook",                      FacebookClientId,  FacebookSecret)),
                        CreateApiButton(new InstagramApi("instagram",                    InstagramClientId, InstagramSecret)),
                        CreateApiButton(new OAuthPasswordApi("myapi",                    "clientid",        "clientsecret",
                                                             "https://serverurl.com",
                                                             "https://tokenurl.com",
                                                             "https://refreshurl.com")),
                        logoutButton
                    }
                }
            });
        }
        public App()
        {
            //Hook up our Forms login page for Basic Auth
            BasicAuthApi.ShowAuthenticator = (IBasicAuthenicator obj) =>
            {
                MainPage.Navigation.PushModalAsync(new LoginPage(obj));
            };

            string FacebookClientId = "457891661734324";
            string FacebookSecret   = "2ef3d25a410dcb9f8b952388790e462f";

            string InstagramClientId = "f2c421d810824581ac758861e56e5340";
            string InstagramSecret   = "2465b93d4cc44355a4ccf32f3eca707a";

#if __ANDROID__
            string GoogleClientId = "646679266669-quj4b4frm8gi4knn6269me7ss9cefj7c.apps.googleusercontent.com";
            string GoogleSecret   = GoogleApi.NativeClientSecret; //"uzj06SA8A66Y9mOA1rSjmQH7";
#else
            //string GoogleClientId = "992461286651-k3tsbcreniknqptanrugsetiimt0lkvo.apps.googleusercontent.com";
            string GoogleClientId = "839224062559-nono05a9u9vpdnrue8irjb4t0sf7e1a7.apps.googleusercontent.com";
            string GoogleSecret   = "Ulyk8Nm45Umzkx7kReEOZHUk";
#endif

            var logoutButton = new Button()
            {
                Text = "Logout"
            };
            logoutButton.Clicked += async(sender, args) =>
            {
                if (_sourceApi != null)
                {
                    _sourceApi.Logout();
                    _sourceApi = null;
                }
            };

            // https://developers.facebook.com/docs/graph-api/reference/user/accounts/
            var facebookListPages = new Button()
            {
                Text = "Facebook : Get Pages"
            };
            facebookListPages.Clicked += async(sender, args) =>
            {
                var apiResult = await _sourceApi.Get("/v4.0/me/accounts");

                Debug.WriteLine(apiResult);

                FacebookAccounts facebookAccounts = JsonConvert.DeserializeObject <FacebookAccounts>(apiResult);

                if (facebookAccounts == null || facebookAccounts.data.Length == 0)
                {
                    await MainPage.DisplayAlert("Information", "User is not associated to any other pages", "Ok");
                }
                else
                {
                    await MainPage.DisplayAlert("Information", $"User is associated {facebookAccounts.data.Length} pages", "Ok");
                }
            };

            //https://developers.facebook.com/docs/graph-api/reference/user/photos/#uploading-photos
            //https://developers.facebook.com/docs/graph-api/photo-uploads
            var facebookUploadPhoto = new Button()
            {
                Text = "Facebook : Upload Photo"
            };
            facebookUploadPhoto.Clicked += async(sender, args) =>
            {
                await Share.RequestAsync(new ShareFileRequest()
                {
                    Title = "Test Upload",
                    File  = new ShareFile(@"..\Appx\Assets\Square44x44Logo.scale-200.png")
                });
            };

            var googlePhotosUpload = new Button()
            {
                Text = "Google Photos : Upload Photo"
            };
            googlePhotosUpload.Clicked += async(sender, args) =>
            {
                Dictionary <string, string> headers = new Dictionary <string, string>()
                {
                    { "X-Goog-Upload-File-Name", "TestPhotoName.png" },
                    { "X-Goog-Upload-Protocol", "raw" }
                };

                var bytes       = File.ReadAllBytes(@"..\Appx\Assets\Square44x44Logo.scale-200.png");
                var httpContent = new ByteArrayContent(bytes);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                var apiResult = await _sourceApi.Post(httpContent, "/v1/uploads", null, headers);

                Debug.WriteLine(apiResult);

                var googleMediaItem = new MediaItems()
                {
                    NewMediaItems = new NewMediaItem[] { new NewMediaItem()
                                                         {
                                                             Description     = "Test IPB Upload",
                                                             SimpleMediaItem = new SimpleMediaItem()
                                                             {
                                                                 UploadToken = apiResult
                                                             }
                                                         } }
                };

                var googleMediaItemJson = JsonConvert.SerializeObject(googleMediaItem);

                var stringContent = new StringContent(googleMediaItemJson);
                stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var newMediaResult = await _sourceApi.Post(stringContent, "/v1/mediaItems:batchCreate");

                Debug.Write(newMediaResult);
            };


            // The root page of your application
            MainPage = new NavigationPage(new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        CreateApiButton(new GoogleApi("google",                          GoogleClientId,    GoogleSecret)
                        {
                            Scopes = new[]
                            {
                                "https://www.googleapis.com/auth/userinfo.email",
                                "https://www.googleapis.com/auth/userinfo.profile",
                                "https://www.googleapis.com/auth/photoslibrary.appendonly"
                            },
                        }),
                        CreateApiButton(new FacebookApi("facebook",                      FacebookClientId,  FacebookSecret)),
                        CreateApiButton(new InstagramApi("instagram",                    InstagramClientId, InstagramSecret)),
                        CreateApiButton(new OAuthPasswordApi("myapi",                    "clientid",        "clientsecret",
                                                             "https://serverurl.com",
                                                             "https://tokenurl.com",
                                                             "https://refreshurl.com")),
                        facebookListPages,
                        facebookUploadPhoto,
                        googlePhotosUpload,
                        logoutButton
                    }
                }
            });
        }