I am creating a login form using Xamarin which accepts email, password fields.
After the user enters his details and clicks on login button, no alert box is displayed. It comes out of the app. Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
using Xamarin.Forms;
using SQLite;
using System.IO;
namespace LoginPage.Views
{
public class AddDetails : ContentPage
{
private Entry _emailEntry;
private Entry _passwordEntry;
private Button _saveButton;
string _dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "myDB.db3");
public AddDetails()
{
this.Title = "Add Details";
StackLayout stackLayout = new StackLayout();
_emailEntry = new Entry();
_emailEntry.Keyboard = Keyboard.Text;
_emailEntry.Placeholder = "Email";
stackLayout.Children.Add(_emailEntry);
_passwordEntry = new Entry();
_passwordEntry.Keyboard = Keyboard.Text;
_passwordEntry.Placeholder = "Password";
stackLayout.Children.Add(_passwordEntry);
_saveButton = new Button();
_saveButton.Text = "Login User";
_saveButton.Clicked += _saveButton_Clicked;
stackLayout.Children.Add(_saveButton);
Content = stackLayout;
}
private async void _saveButton_Clicked(object Sender, EventArgs e)
{
var db = new SQLiteConnection(_dbPath);
db.CreateTable<User>();
var maxPk = db.Table<User>().OrderByDescending(c => c.Id).FirstOrDefault();
User user = new User()
{
Id = (maxPk == null ? 1 : Convert.ToInt32(maxPk.Id) +1),
Email = _emailEntry.Text,
Password = _passwordEntry.Text
};
db.Insert(user);
await DisplayAlert(null, user.Email + "Saved", "Ok");
await Navigation.PopAsync();
}
}
}
Login screen gets displayed, but no alert box which should say Email saved. Also, it comes out of the app abruptly
Have you set
MainPage = new NavigationPage (new Page1Xaml ());
Please follow this link
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/
Related
I added credentials.json in my project. I wrote some code which must make new event in my calendar. When I run my code I also check my Google Calendar but I see there no new event which must be made by my code. Also I don't see token.json in bin/debug folder. How can I solve that issue?
P.S I use the same account
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Highsoft.Web.Mvc.Charts;
using Highsoft.Web.Mvc.Charts.Rendering;
namespace Kyrsovoi
{
public partial class Form1 : Form
{
static string[] Scopes = { CalendarService.Scope.Calendar };
static string ApplicationName = "Google Calendar API .NET Quickstart";
public Form1()
{
InitializeComponent();
}
private void GoogleAPI()
{
UserCredential credential;
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
// List events.
Events events = request.Execute();
if (events.Items != null && events.Items.Count > 0)
{
foreach (var eventItem in events.Items)
{
string when = eventItem.Start.DateTime.ToString();
if (String.IsNullOrEmpty(when))
{
when = eventItem.Start.Date;
}
Console.WriteLine("{0} ({1})", eventItem.Summary, when);
}
}
else
{
}
var ev = new Event();
EventDateTime start = new EventDateTime();
start.DateTime = new DateTime(2020, 10, 17, 11, 0, 0);
EventDateTime end = new EventDateTime();
end.DateTime = new DateTime(2020, 10, 17, 11, 30, 0);
ev.Start = start;
ev.End = end;
ev.Summary = "MyEvent";
ev.Description = "TestScription";
var calendarId = "primary";
Event recurringEvent = service.Events.Insert(ev, calendarId).Execute();
Console.WriteLine("Event created: %s\n", ev.HtmlLink);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form3 newForm1 = new Form3();
newForm1.Show();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
When you have an app that you are testing it hasn't been verified yet. You will see the following screen.
press advanced
If you press the Advanced button you will see the following
authorize the app.
This will let you authorize an unverified application.
I'm developping an application with Xamarin for iOS. I have a page that is filled with a UIStackView that I populate with an image and buttons.
Everything works fine, despite the fact that nothing is visible, but if I click where the buttons should appear, it executes the good behaviour of the button (opening another page).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using CoreGraphics;
using Cirrious.FluentLayouts.Touch;
namespace SmartTransportNatif.iOS
{
public class MainViewController : UIViewController
{
UIButton btn;
JourneyViewController journey;
Dictionary<string, string> favStations;
UIStackView stkView;
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.BackgroundColor = UIColor.White;
Title = "Accueil";
journey = new JourneyViewController();
MyClass pcl = new MyClass();
favStations = pcl.getFavStations();
var img = new UIImageView(View.Frame);
img.Image = UIImage.FromFile("train.png");
var bounds = UIScreen.MainScreen.Bounds;
stkView = new UIStackView(bounds);
stkView.Axis = UILayoutConstraintAxis.Vertical;
stkView.Distribution = UIStackViewDistribution.FillEqually;
stkView.Spacing = 5;
stkView.AddArrangedSubview(img);
View.AddSubview(stkView);
foreach(KeyValuePair<string, string> entry in favStations)
{
addButton(entry.Key, entry.Value);
}
}
void addButton(string name, string station)
{
var btn = UIButton.FromType(UIButtonType.System);
btn.Frame = new CGRect(0, 0, 280, 44);
btn.SetTitle(name, UIControlState.Normal);
btn.BackgroundColor = new UIColor(33,150,234,255);
btn.SetTitleColor(new UIColor(255,255,255,255),
UIControlState.Normal);
btn.TouchUpInside += (sender, e) =>
{
this.NavigationController.PushViewController(journey, true);
};
stkView.AddArrangedSubview(btn);
}
}
}
Does someone see what is wrong or missing?
Actually when i use to execute my program , each time i need new login code to login into Telegram.So i need help in this regard that login code should be saved and not to feed each time the new login code.
Here is my code:
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using TeleSharp.TL;
using TLSharp.Core;
namespace Telegram
{
public partial class Form1 : Form
{ string hash = String.Empty;
public Form1()
{
InitializeComponent();
}
private async void button2_Click(object sender, EventArgs e)
{
string code = textBox2.Text;
TelegramClient client = Utility.Client;
var user = await client.MakeAuthAsync("SENDER_MOBILE", hash, code);
var result = await client.GetContactsAsync();
//find recipient in contacts
var user1 = result.users.lists.Where(x => x.GetType() == typeof(TLUser)).Cast<TLUser>().FirstOrDefault(x => x.phone == "RECEIVER_MOBILE");
//send message
// await client.SendMessageAsync(new TLInputPeerUser() { user_id = user1.id }, "Hiii,Welcome to Telegram");
this.Hide();
Form2 ss = new Form2();
ss.Show();
}
private async void button1_Click(object sender, EventArgs e)
{
Utility.Client = new TelegramClient(APP_ID, "APP_SECRET");
TelegramClient client = Utility.Client;
await client.ConnectAsync();
hash = await client.SendCodeRequestAsync("MY_MOBILE_NUMBER");
button2.Enabled = true;
}
}
}
This is the link for the login:
Log In
If im trying to login manualy in the webbrowser it does nothing but open a popup message ask me if to close the window i click yes and nothing happen. In the regular chrome browser not in the webbrowser when i put in user name and password and click log in it also close the window of the log in automatic refresh the page and im logged in.
But through the webbroswer its never log in. Its not givinig any errors or exceptions just does nothing.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace Champinos
{
public partial class Form1 : Form
{
WebClient webc = new WebClient();
string url = "";
string username = "";
string password = "";
string commit = ""; //this matches the data from Tamper Data
private int timeElapsed;
private string newline1 = "";
private bool complete;
private int count;
public Form1()
{
InitializeComponent();
timeElapsed = 1;
label3.Visible = false;
label5.Visible = false;
complete = false;
count = 1;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
url = "http://www.tapuz.co.il/Common/SignInPage.aspx?backUrl=http://www.tapuz.co.il/Common/SignIn.aspx#loginDone=1";
username = "yasonikolados";
password = "ynnad1972";
commit = "Login";//"Sign+In";
label1.Text = "Completed";
string source = "";
source = webc.DownloadString("http://www.tapuz.co.il/forums2008/forumpage.aspx?forumid=393&r=1");
string start = "data-token=";
string end = " href";
int firstTag = source.IndexOf(start);
int lastTag = source.IndexOf(end, firstTag);
int startIndex = firstTag + start.Length + 1;
int endIndex = lastTag;
string authenticityToken = source.Substring(startIndex, endIndex - startIndex - 30);
webBrowser1.DocumentCompleted -= webBrowser1_DocumentCompleted;
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted2;
string postData = string.Format(
"authenticity_token={2}&session" +
"[username_or_email]={0}&session[password]={1}&commit={3}",
username, password, authenticityToken, commit);
ASCIIEncoding enc = new ASCIIEncoding();
webBrowser1.Navigate("http://www.tapuz.co.il/Common/SignInPage.aspx?backUrl=http://www.tapuz.co.il/Common/SignIn.aspx#loginDone", "", enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
webBrowser1.Navigate("http://www.tapuz.co.il/forums2008/forumpage.aspx?forumid=393&r=1");
}
private void webBrowser1_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = sender as WebBrowser;
string response = b.DocumentText;
if (response.Contains("Sign out"))
{
MessageBox.Show("Login Successful");
}
}
}
}
It is because you are using webBrowser1.Navigate as the last call in your DocumentCompleted event handler. Since you added the webBrowser1_DocumentCompleted2 as the event handler for the DocumentCompleted event prior to the Navigate call, what is happening is that when the call to Navigate happens, it is immediately calling your DocumentCompleted2 function which is signing you out. Instant signin and signout.
If you want to confirm, place breakpoints at the first line of both the DocumentCompleted and DocumentCompleted2 functions and debug it.
I know how to upload a video to Youtube using Youtube API within C#
But I'd like to use the Youtube API to return a date when a particular user last uploaded a video.
My code for uploading a video using C# is below, but I really don't know how to do the above???
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.GData.Client;
using Google.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.GData.YouTube;
using Google.GData.Extensions.Location;
namespace UploadLimit
{
public partial class Form1 : Form
{
string key = "somegarbage";
string appName = "SlowUpload";
string username = "blarg";
string password = "blarg";
public Form1()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
txtFile.Text = dialog.FileName;
}
private void btnUpload_Click(object sender, EventArgs e)
{
YouTubeRequestSettings settings = new YouTubeRequestSettings(appName, key, username, password);
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(txtFile.Text, "video/quicktime");
Video createdVideo = request.Upload(newVideo);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UploadLimit
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
You can get all the user's videos and get the latest date:
var videos = new YouTubeRequest().GetVideoFeed(userId).Entries
DateTime lastUploadDate = videos.Max(video => video.YouTubeEntry.Published)
To get the actual video's title:
var lastVideo = videos.Where(video => video.YouTubeEntry.Published == lastUploadDate).First();
var name = lastVideo.Title