gave92 / fbchat-sharp Goto Github PK
View Code? Open in Web Editor NEWFacebook Messenger client library for C#
License: Other
Facebook Messenger client library for C#
License: Other
I want to perform a validation before list all my contacts and check which of my contacts are currently online.
Hello i using this app for logging my messages but now not working onMessage on netcore logging is without problem but onmessage not works :(
I cant login. Session is null. Is there something i dont understand?
Regards kimmo
I need to run multiple instances, receive and send messages on all of them at the same time.
I am able to easily send messages through the correct account, but when receiving messages, two things happen:
I tried in three ways and always with the same result:
Instantiating a class multiple times:
myClass runInctance1 = new myClass();
myClass1.Login();
myClass runInctance2 = new myClass();
myClass2.Login();
With Thread:
Thread runInstance = new Thread (new ThreadStart (myClass.Login));
runningInstance.Start ();
-With ThreadPool:
ThreadPool.QueueUserWorkItem (myClass.Login);
I believe I am doing something wrong, as I am not an expert in C# and your routine is very well done and working very well.
One more thing. I'm creating a .Net Standard 4.7 library (DLL) and haven't tested it with Core or any other way.
Thanks in advance.
It would be interesting to add a solution folder in the project with some examples as well as we have in fbchat, such as EchoBot.
When i use the API on Window Console. It work well
But when i use API on Window Form. The application is crash and can not close app in normal way.
This is Project i have done: https://drive.google.com/file/d/1G47jJayMH-I-xTOuZ01aZSsY1Or3RnDx/view?usp=sharing
Could you help me to fix that problem or update API?
So thank you if sending me the fixed project
I've got an error with
Something happened: fbchat_sharp.API.FB_LoggingIn
Error logging in
It loads up the interface then the whole thing froze and thats it.
Also
fbchat_sharp.API.FBchatPleaseRefresh: 'Error #1357004
This exception was originally thrown at this call stack:
fbchat_sharp.API.Session._post(string, System.Collections.Generic.Dictionary<string, object>, System.Collections.Generic.Dictionary<string, fbchat_sharp.API.FB_File>, bool, System.Threading.CancellationToken, bool) in Session.cs
[External Code]
fbchat_sharp.API.Session._post(string, System.Collections.Generic.Dictionary<string, object>, System.Collections.Generic.Dictionary<string, fbchat_sharp.API.FB_File>, bool, System.Threading.CancellationToken, bool) in Session.cs
[External Code]
fbchat_sharp.API.Session.graphql_requests(System.Collections.Generic.List<fbchat_sharp.API.GraphQL>) in Session.cs
[External Code]
fbchat_sharp.API.Client.fetchThreadInfo(System.Collections.Generic.List) in Client.cs
[External Code]
fbchat_sharp.API.Client.fetchProfile() in Client.cs
[External Code]
Facebook locks my account although I use Cookie sessions to login every time the app opened with Client.TryLogin()
method
hello please i have problem when i try to start app i give this exception
Exception thrown: 'fbchat_sharp.API.FBchatPleaseRefresh' in fbchat-sharp.dll Refreshing state and resending request
Error information:
{"Error when sending request: Got InternalServerError response"}
Hi there and, firstly, thanks for the work done on this library!
I've had enough of Android and Facebook's bloated engineering so I started working on a lean UWP client for my Lumia 630 phone. Eventually I plan on porting all I need to return to WP10 and its lack of spam or bloat.
Your library exposes a On2FACode callback, which is great, unfortunately, I can't for the life of me figure out a way to ask for user input, wait for user input and read the user's input from a textbox within the same callback.
Now, the quickest, most miserable solution that came to me was polling - and, as expected, this broke the app (serves me right haha). I could set the client as a Singleton and spin the On2FACode callback in a parallel thread then put it to sleep and wake it again when the user finishes typing its 2FA code. I'll probably do just that.
Alternatively, if you could kindly consider exposing in the API something like a MessengerClient.Send2FACode(string input) method, that would be amazing!
Thanks for your time and keep on the awesome work!
DoLogin() always returns false in UWP but it works in WinForms I'm using version 0.2.9
Update: I tried to build fbchat with newer dependencies (but AngleSharp is still at 0.9.11) and I got the this in console when I'm trying to login
Exception thrown: 'fbchat_sharp.API.FBchatException' in fbchat.UWP.dll Exception thrown: 'fbchat_sharp.API.FBchatException' in System.Private.CoreLib.ni.dll fbchat_sharp.API.FBchatException: Login from session failed. at fbchat_sharp.API.Client.<fromSession>d__22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at fbchat_sharp.API.MessengerClient.<TryLogin>d__0.MoveNext(): TryLogin Logging in [email protected]... Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Attempt #1 failed, retrying Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Attempt #2 failed, retrying Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Attempt #3 failed, retrying Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Attempt #4 failed, retrying Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Exception thrown: 'System.NullReferenceException' in fbchat.UWP.dll Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.ni.dll System.NullReferenceException: Object reference not set to an instance of an object. at fbchat_sharp.API.Client.<login>d__33.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at fbchat_sharp.API.MessengerClient.<DoLogin>d__1.MoveNext(): DoLogin
When i use client.markAsRead(threadIds) i got exception "Error #1357031 when sending request: The content you requested cannot be displayed at the moment. It may be temporarily unavailable, the link you clicked on may have expired or you may not have permission to view this page."
Is there any way to retrieve data for a page (threads, messages, etc)?
I was looking for any options on the doLogin method to input the page ID but couldn't found anything.😊Thanks
By the way, amazing library, it's just very hard to find, once this becomes more visible in google im sure it will be huge.
Hi
I’m having trouble logging in to my messenger account that uses phone number instead of e-mail address as user. I only have messenger but no facebook account. If I use my dogs facebook account with e-mail it works great.
Whenever I try to write a chat message facebook locks my account and forces me to change my password. With this great app my code is simple:
MessengerClient client = new FBClient_Simple();
var result = client.DoLogin(Email, Password).Result;
var group = client.searchForGroups(Group).Result;
var msg_uid = client.SendMessage(Message, group[0].uid, ThreadType.GROUP).Result;
r = client.DoLogout().Result;
Does anyone else have this problem? Is there a workaround?
Client client = new Client();
await client.doLogin(login, password);
throws error
Could not load "AngleSharp.Parser.Html.HtmlParser" from "AngleSharp, Version=0.13.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea".
StackTrace: in fbchat_sharp.API.Client.<_login>d__41.MoveNext()
in System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
in fbchat_sharp.API.Client._login()
in fbchat_sharp.API.Client.<doLogin>d__46.MoveNext()
---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.GetResult()
in socialPost.MainWindow.<DoFacebookMessendgerAsync>d__91.MoveNext()
Data: System.Collections.ListDictionaryInternal, Source: fbchat-sharp
in fbchat (python) same loggining info passes fine
I have been trying to login serveral times however I get nothing apart from a simple false boolean. Is there any way to debug why the login is failing? I have tried to use the example project as well but it also fails to login. I have checked email and password multiple times.
Regards
I was following the examples, but I receive the following exception:
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Source=System.Private.CoreLib
StackTrace:
at System.String.Replace(String oldValue, String newValue)
at fbchat_sharp.API.GraphQL_JSON_Decoder.graphql_to_thread(JToken thread)
at fbchat_sharp.API.Client.<>c.b__62_0(JToken node)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List
1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
at fbchat_sharp.API.Client.d__62.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Any idea why this is happening?
If a message contains a .gif, a 'System.NullReferenceException' is thrown. Everything is fine with images and stickers.
Hello please its will be possible to make simple project for you quick guide to your repository?
Thanks in advance for your answer
Recently sendText to any group started returning an error (sending to user is fine) - not sure what this means:
{{
"code": 1675036,
"api_error_code": 33,
"summary": "GraphQL Query Blocked",
"description": "Execution of this query is blocked.",
"is_silent": true,
"is_transient": false,
"requires_reauth": false,
"allow_user_retry": false,
"debug_info": null,
"query_path": null,
"fbtrace_id": "GjMx19I5E7z",
"www_request_id": "AWwSM9Fr8cNEnKY6PTPjkLL",
"sentry_block_user_info": null,
"help_center_id": null
}}
The included example works perfectly, but when I try to implement it in my project, an error is triggered "The header 'Referer' must be modified with the appropriate property or method".
The error is occurring at line 3363 of the Client.cs file
The exception is fired at the caller.
This error is really expected, as some Headers cannot be specified, as documented in HttpWebRequest.Headers.
But I did not find in MQTTnet.Client a way to specify the Referer directly in a property, in this way, I believe that the error is not in your code, but in MQTTnet.
The solution found was to add remark in 3 lines of code, as below and everything works fine.
I don't know why it works well with Net Core, because I didn't evaluate the MQTTnet code, but I believe it is a good idea to report the error to them and request a parse in the header properties and add the restricted headers in their corresponding properties.
Thank you very much and great work.
FB_User.color always returns null and I think it should be ThreadColor
not String
and if it should be a String then it must returns the color hex code
I get this error = Unknown thread type: MARKETPLACE. I can see from your source code that there is no marketplace. Maybe Im doing something wrong? Im on Windows 10 UWP. Thanks.
Dont work any client commands like fetchProfile or fetchUser after authorization. It's just waiting a response all time without any results.
I tested library, found Null reference exception in company chats (quick replies) - see file Message.cs, line 281:
var quick_replies = JToken.Parse(data.get("platform_xmd_encoded")?.Value<string>()).get("quick_replies");
if (quick_replies.Type == JTokenType.Array)
rtn.quick_replies = quick_replies.Select((q) => FB_QuickReply.graphql_to_quick_reply(q)).ToList();
else
rtn.quick_replies = new List<FB_QuickReply>() { FB_QuickReply.graphql_to_quick_reply(quick_replies) };
In two company chats I received quick_replies == null.
Propose small fix:
var quick_replies = JToken.Parse(data.get("platform_xmd_encoded")?.Value<string>()).get("quick_replies");
if (quick_replies != null)
{
if (quick_replies.Type == JTokenType.Array)
rtn.quick_replies = quick_replies.Select((q) => FB_QuickReply.graphql_to_quick_reply(q)).ToList();
else
rtn.quick_replies = new List<FB_QuickReply>() { FB_QuickReply.graphql_to_quick_reply(quick_replies) };
}
Hello please i have problem with onMessage event.
This event stop working after few hours without any error i think its stop listening. and i dont know how to print debug messages :( to console and better to file
I have exception when
"Error #1357004 when sending request: Please try closing and re-opening your browser window" while i try to run a netcore example project. I built project from git,not via nuget.
Hello please i have problem with markalive i have markalive falsr but iam permanently active on fb by my bot so markalive not working i think
Facebook provides me a notification on attempt to login:
We noticed an unusual login from a device or location you don't usually use. Was this you?
I can select yes and also ask it to remember the browser but next login attempts also fail.
I have confirmed the username and password by typing it in manually again to login to facebook.
DoLogin returns false no matter the situation.
// Instantiate FBClient
FBClient client = new FBClient();
// Login with username and password
var logged_in = await client.DoLogin("username", "password");
When "= {" is in a FBThread message, the library will throw an exception:
Unterminated string. Expected delimiter: ". Path 'q0.data.message_thread.messages.nodes[97].message.text', line 1, position 67415. at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote) FacebookDataAnalyzer> at Newtonsoft.Json.JsonTextReader.ParseValue() FacebookDataAnalyzer> at Newtonsoft.Json.JsonTextReader.Read() FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings) FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options) FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings) FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings) FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings) FacebookDataAnalyzer> at Newtonsoft.Json.Linq.JToken.Parse(String json) FacebookDataAnalyzer> at fbchat_sharp.API.GraphQL_JSON_Decoder.graphql_response_to_json(String content) in D:\Projects\fbchat-sharp\fbchat-sharp\API\GraphQl.cs:line 313 FacebookDataAnalyzer> at fbchat_sharp.API.Client._graphql(Dictionary
2 payload, Int32 error_retries) in D:\Projects\fbchat-sharp\fbchat-sharp\API\Client.cs:line 273
FacebookDataAnalyzer> at fbchat_sharp.API.Client.graphql_requests(List1 queries) in D:\Projects\fbchat-sharp\fbchat-sharp\API\Client.cs:line 376 FacebookDataAnalyzer> at fbchat_sharp.API.Client.graphql_request(GraphQL query) in D:\Projects\fbchat-sharp\fbchat-sharp\API\Client.cs:line 387 FacebookDataAnalyzer> at fbchat_sharp.API.Client.fetchThreadMessages(String thread_id, Int32 limit, String before) in D:\Projects\fbchat-sharp\fbchat-sharp\API\Client.cs:line 1215
I've checked it numerous times, and pinpointed issue to this line line 309 - GraphQl.cs:
var json_array = content.Split(new[] { "\n{", " {" }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.StartsWith("{") ? s : "{" + s);
When I call Function FetchThreadMessages(thread_id:=chat_id, limit:=20) to get 20 Messages
It work very well
But if 20 Messages have Big Stikers or Like Stiker like this: https://drive.google.com/file/d/1ipHi9_AjuSvqzZPmaJUSb6kA5bOeJv_D/view?usp=sharing
And I get no Messages. Nothing Happen
Could you help me to fix that Problem?
Thank You So Much :D
I have problems doing login. I do type the correct username/password, but still login is not succesful - boolean from DoLogin is false and no details seem available?
I have an old NodeJS application using facebook-chat-api and with this I can login.
I'm using this under dotnet core (2.1).
Any ideas?
Hey!
Does this library continue to function?
I can't log in, but email and password are correct.
I have done all as you, also checked your examples and they also don't work.
I installed Gave.Libs.Fbchat.
Use Visual Studio 2017.
Hello please its will be possible to capture pictures,videos and voice messages i nean attachmebts and automaticaly download to pc? if yes how many thanks in advance for your answer sinceresly K4r3l01
Hi! I've recently started using your library in my project. Unluckily, sending images doesn't work for me.
Code (FBClient is the the same as in the example):
using System;
using System.IO;
using System.Threading.Tasks;
using fbchat_sharp.API;
namespace bot
{
class Program
{
private static readonly FBClient client = new FBClient();
static async Task Main()
{
Console.WriteLine("fbchat-sharp test");
await client.DoLogin("login", "password");
using (FileStream stream = File.OpenRead("image.png"))
{
await client.sendLocalImage("image.png", stream, null, "0000", ThreadType.GROUP);
}
}
}
}
Exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at fbchat_sharp.API.FBchatFacebookError..ctor(String message, String fb_error_code, String fb_error_message, Int32 request_status_code) in /home/konrad11901/Projects/TEST/fbchat-sharp/API/Models.cs:line 32
at fbchat_sharp.API.Utils.<checkRequest>d__12.MoveNext() in /home/konrad11901/Projects/TEST/fbchat-sharp/API/Utils.cs:line 122
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at fbchat_sharp.API.Client.<_postFile>d__36.MoveNext() in /home/konrad11901/Projects/TEST/fbchat-sharp/API/Client.cs:line 347
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at fbchat_sharp.API.Client.<_uploadImage>d__71.MoveNext() in /home/konrad11901/Projects/TEST/fbchat-sharp/API/Client.cs:line 1482
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at fbchat_sharp.API.Client.<sendLocalImage>d__74.MoveNext() in /home/konrad11901/Projects/TEST/fbchat-sharp/API/Client.cs:line 1565
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at bot.Program.<Main>d__1.MoveNext() in /home/konrad11901/Projects/TEST/bot/Program.cs:line 17
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at bot.Program.<Main>()
I don't know if it's a mistake in my code or the library just doesn't work properly. If it's my mistake, I'd be thankful for pointing it out!
I'm compiling the latest version of the library from source, I'm not using the NuGet package.
This is when I build in release mode and run the certification program. App works fine when I deploy in debug and release on my pc. But when I run the certification on the release package of this app it fails. Also keep in mind that I did not add any nuget packages or other librarys. This is strikly only the the code from this github. Thanks.
Hello i have again exception
Exception thrown: 'fbchat_sharp.API.FBchatPleaseRefresh' in fbchat-sharp.dll
Refreshing state and resending request
after latest update its worked for few days but today its back :(
Stream stream = new MemoryStream(File.ReadAllBytes(@attachment));
var dct = new Dictionary<string, Stream>();
dct.Add(attachment, stream);
msg_uid = await client.sendLocalFiles(dct, message, user, ThreadType.USER);
Is wrong, because throws errors.
fbchat_sharp.API.FBchatException
Error: Message: Some files could not be uploaded: {
"uploadID": null,
"metadata": []
}
Iam able to login with with no authentication and everything is working fine. I turned on 2 step authentication and now its not working. Im using this sample project with no code changes. The Inputbox comes up asking to enter my code but I never get the code to my phone. If I login from the browser it works fine. I get the sms and I can login. But for the app it does not work. I tried both uwp and wpf. The only thing that happens is that Facebook sees a login request and blocks that request. There is no sms being sent. It only gets blocked. Seems like sms 2 step is not being initiated from the app. If i use anything else such as browser or Facebook Messenger I get the sms code and I can login. Please can you help with this? Everything else is working great just this one last thing. Thank you. Here is the error I get from facebook when I check from the browser ===
Review Recent Login
Someone recently tried to log into your account from an unrecognized computer or mobile browser. Because you set up two-factor authentication, your account is temporarily locked. Please complete the following steps to regain access to your account.
This error message happend from Facebook.
"We want to make sure your account is secure
We have recently noticed an unusual activity on your account. We have disconnected you for your safety and that of other users.
To re-access your account, we will guide you through a few steps."
I read it might be cause of creating too much session, so I used this code:
`bool islogged = false;
ConstVars.client = new FBClient_Cookies();
var client = new FBClient_Cookies();
islogged = await ConstVars.client.TryLogin();
if (islogged)
{
Console.WriteLine("got last session.");
}
else
{
Console.WriteLine("new session.");
await ConstVars.client.doLogin("mail", "pass", 1);
}
await ConstVars.client.WriteCookiesAsync();`
It always returns "new session".
Any idea about how to process ?
hello please its will be possible to get user name by thread id?
Thanks in advance for you answer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.