gave92 / fbchat-sharp

Facebook Messenger client library for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong graphql response splitting.

Madoxen opened this issue · comments

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(Dictionary2 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);

I found workaround of my issue, basically i removed " {" delimiter in
var json_array = content.Split(new[] { "\n{", " {" }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.StartsWith("{") ? s : "{" + s);
and it's working just fine. Though it throws exceptions when trying to fetch messages with users that i have no messages, it's fine.

Hello the issue should be solved. Let me know if it works for you.

@gave92 Confirmed, works fine!