error Missing client_id parameter by asp.net? - asp.net

I had this error when getting Facebook user details .
{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException",
"code": 101 }
}
I will use this solution when user click on Facebook tab. I tried to solve this issue more but I cannot .
public partial class DefaultPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FaceBookConnect.Authorize("user_photos,email",
Request.Url.AbsoluteUri.Split('?')[0]);
FaceBookConnect.API_Key = "111111111111111";
FaceBookConnect.API_Secret = "xxxxxxxxxxxxxxxxxx";
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
return;
}
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
pnlFaceBookUser.Visible = true;
//lblId.Text = faceBookUser.Id;
//lblUserName.Text = faceBookUser.UserName;
lblName.Text = faceBookUser.Name;
//lblEmail.Text = faceBookUser.Email;
ProfileImage.ImageUrl = faceBookUser.PictureUrl;
//btnLogin.Enabled = false;
}
}
}
public class FaceBookUser
{
public string Id { get; set; }
public string Name { get; set; }
public string UserName { get; set; }
public string PictureUrl { get; set; }
public string Email { get; set; }
}
Thanks!

I suspect it will be because you're setting the API Key and secret after you are actually calling the authorize method. Try swapping it round like this:
FaceBookConnect.API_Key = "111111111111111";
FaceBookConnect.API_Secret = "xxxxxxxxxxxxxxxxxx";
FaceBookConnect.Authorize("user_photos,email",
Request.Url.AbsoluteUri.Split('?')[0]);
If this doesn't fix it, where are you getting the FaceBookConnect reference from?

Related

elastic search in .net with NEST

I am trying to get ElasticSearch data with NEST in ASP.NET. With a Button that when its clicked my data will be shown in a TextBox.
Do I need to put my database in the project or something? , when I click the button no data is shown.
I am using Visual Studio 2015, .NET Framework 4.6.1
I am a beginner so I can't handle this error that occurred.
I will provide my code.
Error:
NuGet Packages:
namespace ElasticsearchWeb{
public class shekspir
{
public string type { get; set; }
public int line_id { get; set; }
public string play_name { get; set; }
public int speech_number { get; set; }
public float line_number { get; set; }
public string speaker { get; set; }
public string text_entry { get; set; }
}
public partial class Default : System.Web.UI.Page
{
public static Uri GetElasticHost()
{
var host = "http://localhost:9200";
return new Uri(host);
}
public static ElasticClient GetElasticClient(ConnectionSettings settings = null)
{
if (settings == null)
{
var node = GetElasticHost();
var pool = new SingleNodeConnectionPool(node);
settings = new ConnectionSettings(pool);
}
settings.DisableDirectStreaming(true);
var client = new ElasticClient(settings);
return client;
}
public static List<shekspir> GetAllShekspir(int ID)
{
var client = GetElasticClient();
ISearchResponse<shekspir> result = null;
result = client.Search<shekspir>(x => x
.Index("shekspir")
.Query(q => q
.MatchAll())
);
List<shekspir> list = new List<shekspir>();
foreach (var r in result.Hits)
{
shekspir a = r.Source;
list.Add(a);
}
return list;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
List<shekspir> list = GetAllShekspir(1);
foreach (shekspir u in list)
{
litInfo.Text += u.play_name + ": " + u.text_entry + "<br>";
}
}
}}
What version of .Net runtime is your application running? The elastic search Nest API version that you have used is expecting the .Net Standard Version 2.0, which it cannot find.

How to store unique class instances in SQLite?

I'm trying to store some information as a class instance in a SQLite table. The instances need to be unique in their DateTime property. I'm completely new to database programming, and I don't really understand how use SQLite in Xamarin. As new instances are created they need to update the existing instances in the table if they match in their DateTime property.
SQLiteAsyncConnection connection = new SQLiteAsyncConnection(App.FilePath);
await connection.CreateTableAsync<ModulInformationData>();
ModulInformationData data = new ModulInformationData();
data.InitModulInformation(modul);
int rows = 0;
try
{
rows = await connection.UpdateAsync(data);
}catch(Exception e)
{
Console.WriteLine("SQL Update failed " + e.Message);
}
Console.WriteLine("rows updated: " + rows);
if (rows == 0)
{
Console.WriteLine("before insert");
try
{
int key1 = await connection.InsertAsync(data);
Console.WriteLine("after insert: " + key1);
}catch (Exception e)
{
Console.WriteLine("SQL insert failed " + e.Message);
}
}
The ModulInformationData class
public class ModulInformationData
{
[PrimaryKey,AutoIncrement]
public int Id { get; set; }
[Unique]
public DateTime tidspunkt { get; set; }
other properties...
At the moment, I'm catching an error when inserting, but the message only says 'Constraint'. What can I do to make this work?
Do you want to achieve the result like this GIF。
First of all, you can create a class for the database CRUD.
public class NoteDatabase
{
readonly SQLiteAsyncConnection _database;
public NoteDatabase(string dbPath)
{
_database = new SQLiteAsyncConnection(dbPath);
_database.CreateTableAsync<Note>().Wait();
}
public Task<List<Note>> GetNotesAsync()
{
return _database.Table<Note>().ToListAsync();
}
public Task<Note> GetNoteAsync(int id)
{
return _database.Table<Note>()
.Where(i => i.ID == id)
.FirstOrDefaultAsync();
}
public Task<int> SaveNoteAsync(Note note)
{
if (note.ID != 0)
{
return _database.UpdateAsync(note);
}
else
{
return _database.InsertAsync(note);
}
}
public Task<int> DeleteNoteAsync(Note note)
{
return _database.DeleteAsync(note);
}
}
Then there is model class.
public class Note
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Text { get; set; }
[Unique]
public DateTime Date { get; set; }
public string Gender { get; set; }
}
If we want to add or update the data to the database, firstly, we should update the data to the instance, then we could just save this instance to the database like following save click event.
async void OnSaveButtonClicked(object sender, EventArgs e)
{
var note = (Note)BindingContext;
note.Date = DateTime.UtcNow;
note.Gender = (string)myPicker.SelectedItem;
await App.Database.SaveNoteAsync(note);
await Navigation.PopAsync();
}
Here is my demo. you can download it and refer to it.
https://github.com/851265601/databaseDemo

sqlite-net-extensions -- Create Table Async

My problem is that I'm using the CreateTableAsync method and is always returning "0". I researched and saw that this return is a mistake.
I wanted to know what I'm doing wrong.
Class Service Table:
public class SqliteTable
{
private readonly SqliteWrapper _sqliteWrapper;
public SqliteTable()
{
_sqliteWrapper = new SqliteWrapper();
}
private async Task<bool> CheckIfExistTable<T>() where T : new()
{
var connection = _sqliteWrapper.OpenDatabase();
try
{
var result = await connection.Table<T>().CountAsync();
return result.Equals(0);
}
catch (Exception e)
{
Logs.Logs.Error($"Error get count table {typeof(T).Name}: {e.Message}");
return false;
}
}
public async void CreateTable<T>() where T : new()
{
var connection = _sqliteWrapper.OpenDatabase();
if (await CheckIfExistTable<T>())
{
Logs.Logs.Info($"This table {typeof(T).Name} was created");
return;
}
var createTableResult = await connection.CreateTableAsync<T>();
var value = createTableResult.Results.Values.FirstOrDefault();
if (value.Equals(1))
{
Logs.Logs.Info($"Create table {typeof(T).Name}");
}
else
{
throw new Exception($"Error create table {typeof(T).Name}");
}
}
}
I create a Class Model Login. which would be the object to create the database.
public class Login
{
public Login()
{
}
public Login(string user, string password)
{
User = user;
Password = password;
}
public Login(int id, string user, string password)
{
Id = id;
User = user;
Password = password;
}
[PrimaryKey, AutoIncrement, Column("login_id")]
public int Id { get; set; }
[Unique, NotNull, Column("login_user")]
public string User { get; set; }
[NotNull, Column("login_password")] public string Password { get; set; }
}
I create Class CreateTableAsync. Which would be to intanciar the SqliteTable, to call the method CreateTable sending the object to create the database:
protected override void OnStart()
{
try
{
var sqliteTable = new SqliteTable();
sqliteTable.CreateTable<Login>();
}
catch (Exception e)
{
Logs.Logs.Error($"Error init application: {e.Message}");
}
}
Can someone help me?

How to insert gridview data into database as a list(Multiple rows) WCF

I have tried to send data as a string and it is working correctly. but now i want to insert all gridview data as a list into database. Code is here
public interface IService1
{
[OperationContract]
string InsertCustomerDetails(UserDetails userInfo);
[OperationContract]
[WebGet]
List<CustomerTable> GetCustomers();
}
public class UserDetails
{
string Name = string.Empty;
string City = string.Empty;
[DataMember]
public string name
{
get { return Name; }
set { Name = value; }
}
[DataMember]
public string city
{
get { return City; }
set { City = value; }
}
public class Service1 : IService1
{
public string InsertCustomerDetails(UserDetails userInfo)
{
using(DataContext db=new DataContext())
{
CustomerTable customer = new CustomerTable();
customer.Name = userInfo.name;
customer.City = userInfo.city;
db.CustomerTables.Add(customer);
db.SaveChanges();
}
return "name= " + userInfo.name + " city= " + userInfo.city;
}
}
}
WEB Form Code
protected void ButtonADD_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView2.Rows.Count; i++) {
UserDetails info = new UserDetails();
info.name = GridView2.Rows[i].Cells[0].Text;
info.city = GridView2.Rows[i].Cells[1].Text;
obj.InsertCustomerDetails(info);
} }
In Iservice1 class use this
public List<CustomerTable> InsertCustomerDetails(UserDetails userInfo)
{
using(DataContext db=new DataContext())
{
CustomerTable customer = new CustomerTable();
customer.Name = userInfo.name;
customer.City = userInfo.city;
db.CustomerTables.Add(customer);
db.SaveChanges();
return db.CustomerTables.ToList();
}
Use this in interface. Make setter getters in class UserDetails
[OperationContract]
List<CustomerTable> InsertCustomerDetails(UserDetails userInfo);
I Have done this. Just facing problem in Web Form. Any Help will be appriciated. I want to send dqata as list into database

How to consume this web service?

This is my first time creating a web service. I am not sure if my implementation is incorrect, but I am trying to use much like a class. The problem is that when I am trying to consume I am getting confused and not being able to set the values of the properties.
here is the web service.
public class Service1 : System.Web.Services.WebService
{
private bool _isUserActive { get; set; }
private bool _isCredentialValid { get; set; }
public string email { get; set; }
public string pass { get; set; }
public int customerID { get; set; }
[WebMethod]
public bool VerifyUserCredential()
{
bool result = false;
PURLDataContext purl = new PURLDataContext();
try
{
var res = purl.Sel_User(email.ToLower(), pass);
if (res != null)
result = true;
_isUserActive = true;
_isCredentialValid = true;
}
catch (Exception ex)
{
if (ex.Message == "Account is inactive, please contact your administrator!")
{
_isUserActive = false;
_isCredentialValid = false;
}
else
_isCredentialValid = false;
//Invalid credentials.
}
return result;
}
[WebMethod]
public ArrayList retrieveCustomerInfo()
{
ArrayList customerInfo = new ArrayList();
string validate = "Please Validate";
if (_isCredentialValid)
{
PURLDataContext purl = new PURLDataContext();
var customer = purl.Sel_Recipient(customerID);
foreach (var c in customer)
{
customerInfo.Add(c);
}
}
else
customerInfo.Add(validate);
return customerInfo;
}
}
Here is what I am trying to do to consume.
PURLServices.Service1SoapClient webserv = new Service1SoapClient();
bool result;
ArrayOfAnyType array = new ArrayOfAnyType();
webserv.email = "email#email.com";
webserv.pass = "pass";
webserv.customerID = 12345;
result = webserv.VerifyUserCredential();
array = webserv.retrieveCustomerInfo();
Thank you for any help/
You do not want to try to use properties like this. Your method should look more like this:
public bool VerifyUserCredential(string userName, string password)
{
// method body here
}
Probably you would want to return an access token of some sort that the server will cache. This can then be passed into other methods to show that the user is valid.

Resources