I am trying to get the best searches from google, using keyword, and GoogleAPI, but It is always returning "System.Net.WebException: 'The remote server returned an error: (404) Not Found.'"
Am I doing anything wrong, or is it that GoogleAPI is outdated? Last time I checked and downloaded the .dll file was from 2010...
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Collections;
using Microsoft.Win32;
using System.Web;
using System.Net.Mail;
using System.Net.Mime;
using System.ComponentModel;
using System.Net;
using System.Windows;
using Google.Apis.Services;
using Google.Apis.CustomSearchAPI.v1;
//Ignore most using statements, It was imported from my previous code.
namespace TYZDsag
{
internal class Program
{
static void Main(string[] args)
{
var client = new Google.API.Search.GwebSearchClient("https://www.google.com/");
var results = client.Search("uhuhuh", 12);
foreach (var webResult in results)
{
Console.WriteLine("{0}, {1}, {2}", webResult.Title, webResult.Url, webResult.Content);
//listBox1.Items.Add(webResult.ToString());
}
}
}
}
That's not how you initialize a service object using an api key.
using System;
using System.Threading.Tasks;
using Google.Apis.CustomSearchAPI.v1;
using Google.Apis.Services;
namespace customsearch
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var service = new CustomSearchAPIService(new BaseClientService.Initializer()
{
ApiKey = "XXX",
ApplicationName = "xyz",
});
var result = await service.Cse.List().ExecuteAsync();
}
}
}
Method: cse.list
How to create an api key
Related
I am attempting to add an additional column to my logging in SQL Server. In the examples, they give something very similar to the following:
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection<SqlColumn>
{
new SqlColumn { DataType = SqlDbType.NVarChar, DataLength = 20, ColumnName = "B" }
}
}
The problem that I am having is that my compiler keeps complaining about the SqlColumn type usage saying that it is unknown. I am using .Net 4.6.1. What do I need to add to my using? I have the following already:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.IdentityModel.Tokens;
using System.Linq;
using System.Web.Http;
using System.Web.Http.ExceptionHandling;
using System.Net.Http.Formatting;
using Dapper;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Jwt;
using Newtonsoft.Json.Serialization;
using Owin;
using Serilog;
using Serilog.Filters;
using Serilog.Sinks.MSSqlServer;
using SerilogWeb.Classic.WebApi;
EDIT
I have just attempted building an entire new web api project, and the following code also will not work, for some reason I cannot access the SqlColumn type. Note that the error is that the type doesn't exist on the namespace (not an error due to the constructor).
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Owin;
using Owin;
using Serilog;
using Serilog.Sinks.MSSqlServer;
[assembly: OwinStartup(typeof(TestProject.Startup))]
namespace TestProject
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
var x = new Serilog.Sinks.MSSqlServer.SqlColumn();
}
}
}
You will need to Update Serilog.Sinks.MSSqlServer to prereleased version 5.1.3-dev-00232 as its not exist in version 5.1.2
Install-Package Serilog.Sinks.MSSqlServer -Version 5.1.3-dev-00232
Or you can add column using DataColumn type in version 5.1.2 as below
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection<DataColumn>
{
new DataColumn {DataType = typeof (string), ColumnName = "User"},
new DataColumn {DataType = typeof (string), ColumnName = "Other"},
}
};
var log = new LoggerConfiguration()
.WriteTo.MSSqlServer(#"Server=.\SQLEXPRESS;Database=LogEvents;Trusted_Connection=True;", "Logs", columnOptions: columnOptions)
.CreateLogger();
I want to monitor retrieve messages so that the bot can respond to them.
I can send pm using tweetinvi but for some reason, I can't get it to retrieve any of the messages in that account. GetLastMessage always returns a null.
I have tried the following:
in this test, I have a timer that runs every 1s and pols the messages.
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
IEnumerable<IMessage> MSG = controller.GetLatestMessagesReceived(); ; // Message.GetLatestMessagesReceived(100);
if (MSG != null)
{
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
if ((MSG.ElementAt(0).SenderId == ####MYID#####) & (MSG.ElementAt(0).Text == "?"))
{
Message.PublishMessage(tweet, ####MYID#####);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
Console.ResetColor();
Message.DestroyMessage(MSG.ElementAt(0));
}
}
} catch
{
}
}
I have also tried
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
var latestMessagesSent = Message.GetLatestMessagesSent();
var latestMessagesSentParameter = new MessagesSentParameters();
latestMessagesSentParameter.PageNumber = 239823;
var latestMessagesSentFromParameter = Message.GetLatestMessagesSent(latestMessagesSentParameter);
if (latestMessagesSentFromParameter != null)
{
Console.WriteLine("Messages Send : ");
foreach (var mms in latestMessagesSentFromParameter)
{
Console.WriteLine("- '{0}'", mms.Text);
}
}
} catch
{
}
}
I also tried using
IAuthenticatedUser authenticatedUser = User.GetAuthenticatedUser();
authenticatedUser.GetLatestMessagesReceived();
I am using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Collections;
using System.Globalization;
//using System.Threading;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Reflection;
// REST API
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;
// STREAM API
using Tweetinvi.Streaming;
using Stream = Tweetinvi.Stream;
// Others
using Tweetinvi.Exceptions; // Handle Exceptions
using Tweetinvi.Core.Extensions; // Extension methods provided by Tweetinvi
using Tweetinvi.Models.DTO; // Data Transfer Objects for Serialization
using Tweetinvi.Json; // JSON static classes to get json from Twitter.
Your app must have permission to read and write on twitter API.
The following is basically what i did. It is exactly what the example said but it does not go to the URL when I run it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace TestApp.Selenium_Basics
{
class TestExercise01
{
public void TestExercise01Run()
{
IWebDriver driver = new FirefoxDriver();
driver.Url = #"http://www.facebook.com";
}
}
}
The line below will not work:
driver.Url = #"http://www.facebook.com";
Try this instead:
driver.Navigate().GoToUrl(#"http://www.facebook.com");
I'm new to the threading world and trying to make my application works with threads. Here is what I got:
public static void ThreadProc()
{
Thread.Sleep(500);
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("SuperMMFofDoom", MemoryMappedFileRights.ReadWrite);
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(0, sizeof(double)*3 + sizeof(int) *2);
Image imgS = new Image();
ImageTrigger myMessage;
Mutex imgMutex = new Mutex(false, "imgMutex");
while (threadRunning)
{
imgMutex.WaitOne();
accessor.Read(0, out myMessage);
// [...]
Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(delegate()
{
// [...]
}),
new object[] { imgS, myMessage.performance }
);
imgMutex.ReleaseMutex();
}
}
This thing does compile when I comment all the Dispatcher.Invoke(). If I don't, I get an error about System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate, object) and it does not compile.
Any ideas?
I'm using VS2010 on Windows 7 Pro x64. This is a C# WPF project which also make use of some C++ DLLs also compiled in the same project. Finally, here is the header of the file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.IO.MemoryMappedFiles;
using Common;
You should not be creating a new Action just casting your delegate as one:
Async:
Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)delegate()
{
});
Sync:
Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});
Or if your not on a control or window:
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});
I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.
using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string InstallPath, WoWExe, PatchPath;
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey LocalMachineKey_Existence;
MessageBox.Show("Browse your install location.", "Select Wow.exe");
OpenFileDialog BrowseInstallPath = new OpenFileDialog();
BrowseInstallPath.Filter = "wow.exe|*.exe";
if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
{
InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
WoWExe = InstallPath + "\\wow.exe";
PatchPath = InstallPath + "\\Data\\";
LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\ExistenceWoW");
LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
}
}
}
}
The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S
Look at this picture:
http://img21.imageshack.us/img21/2829/regedita.jpg
My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.
Can you debug and see what InstallPath contains?
Try it with Path.Combine instead of string concatenation, e.g.:
WowExe = Path.Combine(InstallPath, "wow.exe");
PatchPath = Path.Combine(InstallPath, #"\Data\");