public ActionResult Index(IndexViewModel model) { if (ModelState.IsValid) { // In case of difficulty for the callbac, set up your .hosts (Windows) or etc/hosts file to point a live domain to your localhost IP. such as: // 127.0.0.1 xyz.com // where xyz.com is your real domain. // following auth process : http://getpocket.com/developer/docs/authentication var myPocket = new PocketClient(model.ConsumerKey, Request.Url.AbsoluteUri + Url.Action("Authorized")); // Step 2: Obtain a request token //To begin the Pocket authorization process, //your application must obtain a request token from our servers by making a POST request. myPocket.GetAccessToken(); if (myPocket.AccessToken != null) { //Step 3: Redirect user to Pocket to continue authorization //Once you have a request token, //you need to redirect the user to Pocket to authorize your application's request token. var url = myPocket.PocketAuthorizePageUrl(); this.Session["GetPocketObject"] = myPocket; return(Redirect(url)); } return(new HttpUnauthorizedResult()); } return(View(model)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { try { var requestToken = StorageHelper.Retrieve("request_token"); if (requestToken != null) { var accessToken = await _pocketOauth.GetAccessTokenAsync(requestToken); StorageHelper.Save("access_token", accessToken); TokenContent.Text = String.Format("Request token = {0}, Access token = {1}", requestToken, accessToken); _pocketClient = new PocketClient("11138-795ce1635b4487cac002aa0b", accessToken); var pocketObject = await _pocketClient.GetAllUnreadAsync(); TokenContent.Text = pocketObject.First().Excerpt; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Creates and adds a few ItemViewModel objects into the Items collection. /// </summary> public async Task LoadData() { // !! please don't misuse this account !! PocketClient client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); List<PocketSharp.Models.PocketItem> items = null; try { items = (await client.Get()).ToList(); items.ForEach(item => { this.Items.Add(new ItemViewModel() { ID = item.ID.ToString(), LineOne = item.Title, LineTwo = item.Uri.ToString() }); }); } catch (PocketException ex) { Debug.WriteLine(ex.Message); } this.IsDataLoaded = true; }
private static async Task <int> Main(string[] args) { Console.WriteLine("Hello World!"); var _client = new PocketClient(_config.PocketConsumerKey, callbackUri: _config.PocketRedirectUri); string requestCode = await _client.GetRequestCode(); Console.WriteLine(_client.GenerateRegistrationUri(requestCode).ToString()); Console.WriteLine("Press enter after authorizing app..."); Console.ReadLine(); PocketUser pocketUser = await _client.GetUser(requestCode); IUserService userService = UserService.BuildUserService(_config.StorageConnectionString); Console.WriteLine("Input your kindle email:"); var kindleEmail = Console.ReadLine(); var user = new User() { AccessCode = pocketUser.Code, PocketUsername = pocketUser.Username, KindleEmail = kindleEmail, LastProcessingDate = DateTime.UtcNow }; await userService.AddUserAsync(user); Console.WriteLine("Bye World!"); Console.ReadLine(); return(0); }
/// <summary> /// Creates and adds a few ItemViewModel objects into the Items collection. /// </summary> public async Task LoadData() { // !! please don't misuse this account !! PocketClient client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); List <PocketSharp.Models.PocketItem> items = null; try { items = (await client.Get()).ToList(); items.ForEach(item => { this.Items.Add(new ItemViewModel() { ID = item.ID.ToString(), LineOne = item.Title, LineTwo = item.Uri.ToString() }); }); } catch (PocketException ex) { Debug.WriteLine(ex.Message); } this.IsDataLoaded = true; }
private async Task AuthPocketAsync() { if (!AuthPocketViaSavedAccessToken()) { pocketClient = new PocketClient(Secrets.PocketAPIConsumerKey); Uri callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri(); RequestToken requestToken = await pocketClient.ObtainRequestTokenAsync( callbackUri); Uri requestUri = pocketClient.ObtainAuthorizeRequestTokenRedirectUri(requestToken, callbackUri); WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateSilentlyAsync(requestUri); if (result.ResponseStatus != WebAuthenticationStatus.Success) { result = await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.None, requestUri); } AccessToken token = await pocketClient.ObtainAccessTokenAsync(requestToken); ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; string tokenString = JsonSerializer.Serialize(token); localSettings.Values.Add("accessToken", tokenString); } }
public static async Task AuthPocket(string accessCode = null) { if (string.IsNullOrEmpty(accessCode) && AuthBrowserAction != null) { pocketClient = new PocketClient(POCKETCONSUMERKEY) { CallbackUri = "https://derekantrican.github.io/authsuccess" }; string requestCode = await pocketClient.GetRequestCode(); AuthBrowserAction.Invoke(pocketClient.GenerateAuthenticationUri().ToString()); PocketUser user; while (true) { try { user = await pocketClient.GetUser(requestCode); break; } catch { } Thread.Sleep(500); } accessCode = user.Code; SaveAccessCodeAction?.Invoke(accessCode); } pocketClient = new PocketClient(POCKETCONSUMERKEY, accessCode); }
private async void Button_Click(object sender, RoutedEventArgs e) { // !! please don't misuse this account !! PocketClient client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); List<PocketSharp.Models.PocketItem> items = null; try { items = (await client.Get()).ToList(); items.ForEach(item => { Sites.Add(new Site() { Content = item.Title, Url = item.Uri.ToString() }); }); } catch (PocketException ex) { Debug.Write(ex.Message); } }
public async Task <Uri> LoginUriAsync() { client = new PocketClient(ApiKeys.Pocket, callbackUri: App.PocketProtocol); string requestCode = await client.GetRequestCode(); return(client.GenerateAuthenticationUri()); }
private async void Button_Click(object sender, RoutedEventArgs e) { // !! please don't misuse this account !! PocketClient client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); List <PocketSharp.Models.PocketItem> items = null; try { items = await client.Get(); items.ForEach(item => { Sites.Add(new Site() { Content = item.Title, Url = item.Uri.ToString() }); }); } catch (PocketException ex) { Debug.Write(ex.Message); } }
// setup public TestsBase() { // !! please don't misuse this account !! client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); }
static void Main(string[] args) { PocketClient client = new PocketClient(consumerKey: "34389-adecd115936b95b8e70517f0"); List <PocketItem> items = client.Search("css").Result.ToList(); items.ForEach( item => Console.WriteLine(item.ID + " | " + item.Title) ); }
public StressTests() : base() { // !! please don't misuse this account !! client = new PocketClient( consumerKey: "20000-786d0bc8c39294e9829111d6", callbackUri: "http://frontendplay.com", accessCode: "9b8ecb6b-7801-1a5c-7b39-2ba05b" ); urls = File.ReadAllLines("../../url-100000.csv").Select(item => item.Split(',')[1]); }
static async Task PocketAdd(string url) { const string consumerKey = "[YOUR_CONSUMER_KEY]"; const string accessCode = "[YOUR_ACCESS_CODE]"; PocketClient client = new PocketClient(consumerKey, accessCode); PocketItem newItem = await client.Add( new Uri(url), new string[] { "boxscore" } ); }
private bool AuthPocketViaSavedAccessToken() { ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (localSettings.Values.TryGetValue("accessToken", out object accessTokenObject)) { AccessToken accessToken = JsonSerializer.Deserialize <AccessToken>(accessTokenObject.ToString()); pocketClient = new PocketClient(accessToken); return(true); } return(false); }
static void Main(string[] args) { PocketClient pocket = new PocketClient(CONSUMER_KEY); string authUrl = pocket.GetAuthUrlAsync().Result; Console.WriteLine("AuthUrl: " + authUrl); Console.WriteLine("Please auth action."); Console.ReadLine(); if (pocket.SendAuthCompleteAsync().Result) { Console.WriteLine("Complete."); pocket.Add("https://getpocket.com/developer/docs/v3/add", tags: new[] { "test" }).Wait(); } }
public static async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { var _config = new ConfigBuilder(context.FunctionAppDirectory).Build(); var _emailSender = new MailgunSender(_config.MailGunSenderOptions.ApiKey, _config.MailGunSenderOptions.HostEmail); var _client = new PocketClient(_config.PocketConsumerKey, callbackUri: _config.PocketRedirectUri); string requestBody = new StreamReader(req.Body).ReadToEnd(); RegisterRequest request = JsonConvert.DeserializeObject <RegisterRequest>(requestBody); if (!IsValidEmail(request.KindleEmail)) { log.LogError($"Not valid email: {request.KindleEmail}."); return(new BadRequestObjectResult("email provided is not valid")); } PocketUser pocketUser = new PocketUser(); try { pocketUser = await _client.GetUser(request.RequestCode); } catch (PocketException pocketException) { log.LogError($"Something went wrong: {pocketException.Message}."); return(new BadRequestObjectResult(pocketException.Message)); } IUserService userService = UserService.BuildUserService(_config.StorageConnectionString); await userService.AddUserAsync(new User { AccessCode = pocketUser.Code, PocketUsername = pocketUser.Username, KindleEmail = request.KindleEmail, LastProcessingDate = DateTime.UtcNow, Token = Guid.NewGuid().ToString() }); await SendWelcomeEmail(_emailSender, request.KindleEmail); log.LogInformation($"Successfully registered user: {request.KindleEmail}."); return(new OkObjectResult("Registration successful")); }
public static async System.Threading.Tasks.Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ExecutionContext context) { Config _config = new ConfigBuilder(context.FunctionAppDirectory).Build(); var _client = new PocketClient(_config.PocketConsumerKey, callbackUri: _config.PocketRedirectUri, isMobileClient: false); string requestCode = await _client.GetRequestCode(); var result = new { RequestCode = requestCode, RegistrationLink = _client.GenerateRegistrationUri(requestCode) }; return(new OkObjectResult(JsonConvert.SerializeObject(result))); }
static void Main(string[] args) { var clientId = Environment.GetEnvironmentVariable("POCKET_CLIENT_ID"); var secret = Environment.GetEnvironmentVariable("POCKET_SECRET"); var testPhone = Environment.GetEnvironmentVariable("POCKET_PHONE"); if (string.IsNullOrWhiteSpace(clientId)) { Console.WriteLine("\"POCKET_CLIENT_ID\" environment variable is missing!"); return; } if (string.IsNullOrWhiteSpace(secret)) { Console.WriteLine("\"POCKET_SECRET\" environment variable is missing!"); return; } var client = new PocketClient(clientId, secret, Platform.Test); // CheckAuthExample(client).Wait(); CheckPhoneExample(client, testPhone).Wait(); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ExecutionContext context) { Config _config = new ConfigBuilder(context.FunctionAppDirectory).Build(); string articleId = req.Query["articleId"]; string userHash = req.Query["token"]; if (articleId == null || userHash == null) { return(new BadRequestObjectResult("no token or articleId")); } var userService = UserService.BuildUserService(_config.StorageConnectionString); var user = await userService.FindUserWithToken(userHash); if (user == null) { return(new BadRequestObjectResult("invalid user hash")); } var pocketClient = new PocketClient(_config.PocketConsumerKey, user.AccessCode); var article = await pocketClient.Get(articleId); if (article == null) { return(new BadRequestObjectResult("invalid article id")); } var success = await pocketClient.Favorite(article); //todo have html results return(success ? (ActionResult) new OkObjectResult("Archiving successful") : new BadRequestObjectResult("Something went wrong")); }
public async Task LoadData() { // !! please don't misuse this account !! PocketClient client = new PocketClient( consumerKey: "15396-f6f92101d72c8e270a6c9bb3", callbackUri: "http://frontendplay.com", accessCode: "80acf6c5-c198-03c0-b94c-e74402" ); List <PocketSharp.Models.PocketItem> items = null; try { items = (await client.Get()).ToList(); foreach (var item in items) { Items.Add(item); } } catch (PocketException ex) { Debug.WriteLine(ex.Message); } }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ExecutionContext context) { Config _config = new ConfigBuilder(context.FunctionAppDirectory).Build(); string articleId = req.Query["articleId"]; string userHash = req.Query["token"]; if (articleId == null || userHash == null) { return(new HtmlResponseMessage(HttpStatusCode.BadRequest, "no token or articleId")); } var userService = UserService.BuildUserService(_config.StorageConnectionString); var user = await userService.FindUserWithToken(userHash); if (user == null) { return(new HtmlResponseMessage(HttpStatusCode.Unauthorized, "invalid user hash")); } var pocketClient = new PocketClient(_config.PocketConsumerKey, user.AccessCode); var article = await pocketClient.Get(articleId); if (article == null) { return(new HtmlResponseMessage(HttpStatusCode.NotFound, "invalid article id")); } var success = await pocketClient.Favorite(article); return(success ? new HtmlResponseMessage(HttpStatusCode.OK, "Starring successful") : new HtmlResponseMessage(HttpStatusCode.InternalServerError, "Something went wrong")); }
static async Task CheckPhoneExample(PocketClient client, string testPhone) { Console.WriteLine(await client.CheckPhoneAsync(testPhone)); }
static async Task CheckAuthExample(PocketClient client) { Console.WriteLine(await client.CheckAuthAsync()); }
public bool CheckLogin() { client = LoadCacheClient(); return(client != null); }
public PocketCache(PocketClient pocketClient) { _pocketClient = pocketClient; }
public PocketAccount() { _client = new PocketClient(ConsumerKey); }
public PocketAccount(string accessCode) { _client = new PocketClient(ConsumerKey, accessCode); }