我想从Whats App上的联系人中获取消息(当然,我认为是类似oAuth的东西),但据我发现,哪些应用没有API。所以我尝试在WebBrowser中加载Web版本并从那里获得消息,但我无法使其工作。如何从特定联系人获取消息?
它开始加载页面来请求扫描二维码,但它重定向到一个页面,说当前的浏览器不支持。所以我尝试在IE上使用仿真模式,将其设置为IE11并将http用户代理更改为正确的IE11,但它也不起作用。我怎样才能解决这个问题?
这里是我当前的代码:
public partial class Form1 : Form
{
[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(
int dwOption, string pBuffer, int dwBufferLength, int dwReserved);
const int URLMON_OPTION_USERAGENT = 0x10000001;
const int URLMON_OPTION_USERAGENT_REFRESH = 0x10000002;
const string usersAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetEmulation();
ChangeUserAgent(usersAgent);
}
public static void ChangeUserAgent(string UserAgent)
{
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, null, 0, 0);
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, UserAgent, UserAgent.Length, 0);
}
public void SetEmulation()
{
const int BROWSER_EMULATION_IE11 = 0x2AF9;
var appName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
appName, BROWSER_EMULATION_IE11, RegistryValueKind.DWord);
}
void UnsetEmulation()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true))
{
var appName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
key.DeleteValue(appName);
}
}
}
,我尝试打开这样的:
webBrowser1.Navigate(@"http://web.whatsapp.com/");
AA完全不同的解决方案来实现,这是非常可喜的。
我正在使用Cef浏览器工作......我放弃.NET本地网页浏览器 – Jack
如果您使用IE11浏览,您将在主页中看到支持的浏览器。 *我们推荐使用WhatsApp以及以下浏览器之一:Google Chrome,Mozilla Firefox,Opera WhatsApp也支持:Microsoft Edge,Safari(仅MacOS 10.8+)*看起来该网站根本不支持IE。 –