forked from CommunityToolkit/WindowsCommunityToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedInPage.xaml.cs
More file actions
99 lines (82 loc) · 2.89 KB
/
Copy pathLinkedInPage.xaml.cs
File metadata and controls
99 lines (82 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.Toolkit.Services.LinkedIn;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class LinkedInPage : Page
{
public LinkedInPage()
{
InitializeComponent();
}
private async void ConnectButton_Click(object sender, RoutedEventArgs e)
{
if (!await Tools.CheckInternetConnectionAsync())
{
return;
}
if (string.IsNullOrEmpty(ClientId.Text) || string.IsNullOrEmpty(ClientSecret.Text) || string.IsNullOrEmpty(CallbackUri.Text))
{
return;
}
var oAuthTokens = new LinkedInOAuthTokens
{
ClientId = ClientId.Text,
ClientSecret = ClientSecret.Text,
CallbackUri = CallbackUri.Text
};
LinkedInService.Instance.Initialize(oAuthTokens, LinkedInPermissions.ReadBasicProfile | LinkedInPermissions.WriteShare);
var loggedIn = await LinkedInService.Instance.LoginAsync();
if (loggedIn)
{
var profile = await LinkedInService.Instance.GetUserProfileAsync();
ProfileImage.DataContext = profile;
ProfileImage.Visibility = Visibility.Visible;
ShareBox.Visibility = Visibility.Visible;
}
}
private async void ShareButton_Click(object sender, RoutedEventArgs e)
{
if (!await Tools.CheckInternetConnectionAsync())
{
return;
}
if (string.IsNullOrEmpty(ShareText.Text))
{
return;
}
await LinkedInService.Instance.ShareActivityAsync(ShareText.Text);
var message = new MessageDialog("Share sent to LinkedIn");
await message.ShowAsync();
}
private void ShareExpandButton_Click(object sender, RoutedEventArgs e)
{
if (SharePanel.Visibility == Visibility.Visible)
{
HideSharePanel();
}
else
{
ShowSharePanel();
}
}
private void ShowSharePanel()
{
ShareExpandButton.Content = "";
SharePanel.Visibility = Visibility.Visible;
}
private void HideSharePanel()
{
ShareExpandButton.Content = "";
SharePanel.Visibility = Visibility.Collapsed;
}
}
}