├── .gitattributes ├── .gitignore ├── FacebookApiSharp.sln ├── LICENSE ├── README.md └── src └── FacebookApiSharp ├── API ├── Builder │ ├── FacebookApiBuilder.cs │ └── IFacebookApiBuilder.cs ├── FacebookApi.cs ├── FacebookApiConstants.cs ├── IFacebookApi.cs └── Processors │ ├── AccountProcessor.cs │ ├── IAccounProcessor.cs │ ├── IMediaProcessor.cs │ ├── IMessagingProcessor.cs │ ├── IUserProcessor.cs │ ├── MediaProcessor.cs │ ├── MessagingProcessor.cs │ └── UserProcessor.cs ├── Classes ├── DeviceInfo │ ├── AndroidDevice.cs │ ├── AndroidDeviceGenerator.cs │ ├── AndroidDevices.cs │ ├── AndroidVersion.cs │ └── AndroidVersionList.cs ├── FacebookDataPageResult.cs ├── HttpRequestProcessor.cs ├── IHttpRequestProcessor.cs ├── IRequestDelay.cs ├── IResult.cs ├── Models │ ├── FacebookFriends.cs │ ├── FacebookLoginSession.cs │ ├── FacebookMessage.cs │ └── Messaging │ │ ├── FacebookInboxFriends.cs │ │ └── FacebookInboxTopFriends.cs ├── PaginationParameters.cs ├── RequestDelay.cs ├── Responses │ ├── DefaultResponse.cs │ ├── FacebookActorResponse.cs │ ├── FacebookFailureLoginResponse.cs │ ├── FacebookLocaleLanguages.cs │ ├── FacebookLoggingEvents.cs │ ├── FacebookLoginApprovalsKeyResponse.cs │ ├── FacebookLoginSessionResponse.cs │ ├── FacebookMessageResponse.cs │ ├── FacebookMobileGateKeepers.cs │ ├── FacebookNetworkInterfaceResponse.cs │ ├── FacebookPageResult.cs │ ├── FacebookZeroHeadersPingParams.cs │ ├── Media │ │ ├── FacebookLinkPreviewResponse.cs │ │ └── FacebookStoryResponse.cs │ ├── Messaging │ │ └── FacebookInboxFriendsResponse.cs │ └── Users │ │ ├── FacebookLoginActivityResponse.cs │ │ ├── FacebookLogout.cs │ │ ├── FacebookSearchData.cs │ │ └── Friends.cs ├── Result.cs ├── ResultInfo.cs ├── SessionHandlers │ ├── FileSessionHandler.cs │ └── ISessionHandler.cs ├── StateData.cs └── UserSessionData.cs ├── Converters ├── FacebookInboxFriendsConverter.cs ├── FacebookInboxTopFriendsConverter.cs ├── FacebookLoginSessionConverter.cs ├── FacebookMessageConverter.cs ├── Friends │ └── FacebookFriendsConverter.cs ├── IObjectConverter.cs └── ObjectsConverter.cs ├── Enums ├── FacebookLoginResult.cs └── ResponseType.cs ├── FacebookApiSharp.csproj ├── Helpers ├── CryptoHelper.cs ├── DateTimeHelper.cs ├── ExtensionsHelper.cs ├── GlobalSuppressions.cs ├── HttpExtensions.cs ├── HttpHelper.cs ├── HttpUtility.cs ├── PemKeyUtils.cs ├── SerializationHelper.cs └── UriCreator.cs ├── LICENSE.txt └── Logger ├── DebugLogger.cs ├── FileDebugLogger.cs ├── IFacebookLogger.cs └── LogLevel.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | *.zip 365 | -------------------------------------------------------------------------------- /FacebookApiSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32929.385 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FacebookApiSharp", "src\FacebookApiSharp\FacebookApiSharp.csproj", "{0DFB5750-CA6A-4214-825A-F7000BFD2A8B}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EE5B75BE-C8EB-4D0D-AD04-BB0734D7EFF6}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0DFB5750-CA6A-4214-825A-F7000BFD2A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {0DFB5750-CA6A-4214-825A-F7000BFD2A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {0DFB5750-CA6A-4214-825A-F7000BFD2A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {0DFB5750-CA6A-4214-825A-F7000BFD2A8B}.Release|Any CPU.Build.0 = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | GlobalSection(NestedProjects) = preSolution 25 | {0DFB5750-CA6A-4214-825A-F7000BFD2A8B} = {EE5B75BE-C8EB-4D0D-AD04-BB0734D7EFF6} 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {6A089D6D-13BF-4E95-AF1D-400EF12AAAEE} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ramtin Jokar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FacebookApiSharp 2 | A Tiny Private Facebook API for .NET based on Android version. 3 | 4 | IRANIAN DEVELOPERS 5 | 6 | ----- 7 | 8 | Features: 9 | - Login with facebook using email/phone and password 10 | - Search users 11 | - Get friends 12 | - Get direct inbox friends 13 | - Get direct top friends 14 | - Send direct text 15 | - Make new post 16 | - Upload photo 17 | 18 | ## Note 19 | This library is NOT intend to be getting new updates/features by me(Ramtin). 20 | 21 | I just shared the project to help people for their start. 22 | 23 | This library won't publish to Nuget.org by me. 24 | 25 | Build this library by yourself. 26 | If you have problem with building it, try removing some platforms in the [FacebookApiSharp.csproj in line 4](https://github.com/ramtinak/FacebookApiSharp/blob/c67d0c208c3ee4ebdb643c015ffe7c06a891ace8/src/FacebookApiSharp/FacebookApiSharp.csproj#L4). 27 | 28 | ## Sample 29 | You won't get any sample for this, this library is just like [InstagramApiSharp](https://github.com/ramtinak/InstagramApiSharp)'s library, 30 | So, if you know how to use [InstagramApiSharp](https://github.com/ramtinak/InstagramApiSharp)'s library, you can use [FacebookApiSharp](https://github.com/ramtinak/FacebookApiSharp)'s library as well. 31 | 32 | ```C# 33 | var userSession = new UserSessionData 34 | { 35 | User = "Facebook Email or Phone number", 36 | Password = "Facebook Password" 37 | }; 38 | 39 | IFacebookApi FacebookApi = FacebookApiBuilder.CreateBuilder() 40 | .SetUser(userSession) 41 | //.UseLogger(new FileDebugLogger(LogLevel.All)) 42 | .UseLogger(new DebugLogger(LogLevel.All)) 43 | .SetRequestDelay(RequestDelay.FromSeconds(0, 1)) 44 | // Session handler, set a file path to save/load your state/session data 45 | .SetSessionHandler(new FileSessionHandler { FilePath = StateFile }) 46 | 47 | //// Setting up proxy if you needed 48 | //.UseHttpClientHandler(httpClientHandler) 49 | .Build(); 50 | 51 | FacebookApi.SimCountry = FacebookApi.NetworkCountry = "us"; // lower case < us => united states 52 | FacebookApi.ClientCountryCode = "US"; // most be upper case united states 53 | FacebookApi.AppLocale = FacebookApi.DeviceLocale = "en_US"; // if you want en_US , no need to set these 54 | 55 | 56 | // load old session 57 | FacebookApi.SessionHandler?.Load(); 58 | 59 | if (!FacebookApi.IsUserAuthenticated) // if we weren't logged in 60 | { 61 | await FacebookApi.SendLoginFlowsAsync(); 62 | 63 | var loginResult = await FacebookApi.LoginAsync(); 64 | if (loginResult.Succeeded)// logged in 65 | { 66 | //// library will saves session automatically, so no need to do this: 67 | //FacebookApi.SessionHandler?.Save(); 68 | Connected(); 69 | // after we logged in, we need to sends some requests 70 | await FacebookApi.SendAfterLoginFlowsAsync(); 71 | } 72 | else 73 | { 74 | switch (loginResult.Value) 75 | { 76 | case FacebookLoginResult.WrongUserOrPassword: 77 | MessageBox.Show("Wrong Credentials (user or password is wrong)"); 78 | 79 | break; 80 | 81 | case FacebookLoginResult.RenewPwdEncKeyPkg: 82 | MessageBox.Show("Press login button again"); 83 | break; 84 | } 85 | } 86 | } 87 | else 88 | { 89 | Connected(); 90 | } 91 | ``` 92 | 93 | ## Terms and conditions 94 | - Use this Library at your own risk. 95 | - Don't ask me anything about this library, just use it and figure it out the problem you might ran into. 96 | 97 | ## Warning 98 | Note 1: This library doesn't send all the request(s) that is sending by real Facebook app. 99 | 100 | Note 2: This library doesn't send any logs to Facebook server. 101 | 102 | ## License 103 | MIT. 104 | 105 | ## Legal 106 | This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Facebook or any of its affiliates or subsidiaries. This is an independent and unofficial API wrapper. 107 | 108 | 109 | Iranian developers - (c) 2022 | Paeez 1401. 110 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Builder/FacebookApiBuilder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.SessionHandlers; 10 | using FacebookApiSharp.Logger; 11 | using System; 12 | using System.Net; 13 | using System.Net.Http; 14 | 15 | namespace FacebookApiSharp.API.Builder 16 | { 17 | public class FacebookApiBuilder : IFacebookApiBuilder 18 | { 19 | private IRequestDelay _delay = RequestDelay.Empty(); 20 | private AndroidDevice _device; 21 | private HttpClient _httpClient; 22 | private HttpClientHandler _httpHandler = new HttpClientHandler() 23 | { 24 | UseProxy = false, 25 | AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate 26 | }; 27 | private IHttpRequestProcessor _httpRequestProcessor; 28 | private IFacebookLogger _logger; 29 | private ISessionHandler _sessionHandler; 30 | private UserSessionData _user; 31 | private string _language = "en-US"; 32 | private FacebookApiBuilder() { } 33 | 34 | public IFacebookApi Build() 35 | { 36 | if (_user == null) 37 | _user = UserSessionData.Empty; 38 | 39 | if (_httpHandler == null) _httpHandler = new HttpClientHandler 40 | { 41 | UseProxy = false, 42 | AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate 43 | }; 44 | 45 | if (_httpClient == null) 46 | _httpClient = new HttpClient(_httpHandler) { BaseAddress = new Uri(FacebookApiConstants.FACEBOOK_URL) }; 47 | 48 | if (_device == null) 49 | _device = AndroidDeviceGenerator.GetRandomAndroidDevice(); 50 | 51 | if (_httpRequestProcessor == null) 52 | _httpRequestProcessor = 53 | new HttpRequestProcessor(_delay, 54 | _httpClient, 55 | _httpHandler, _logger); 56 | 57 | var facebookApi = new FacebookApi(_user, _logger, _device, _httpRequestProcessor); 58 | if (!string.IsNullOrEmpty(_language)) 59 | { 60 | // no need to add StartupCountry 61 | facebookApi.AppLocale = facebookApi.DeviceLocale = _language.Replace("-", "_"); 62 | facebookApi.AcceptLanguage = _language; 63 | } 64 | if (_sessionHandler != null) 65 | { 66 | _sessionHandler.FacebookApi = facebookApi; 67 | facebookApi.SessionHandler = _sessionHandler; 68 | } 69 | return facebookApi; 70 | } 71 | 72 | public IFacebookApiBuilder UseLogger(IFacebookLogger logger) 73 | { 74 | _logger = logger; 75 | return this; 76 | } 77 | 78 | public IFacebookApiBuilder UseHttpClient(HttpClient httpClient) 79 | { 80 | if (httpClient != null) 81 | httpClient.BaseAddress = new Uri(FacebookApiConstants.FACEBOOK_URL); 82 | 83 | _httpClient = httpClient; 84 | return this; 85 | } 86 | 87 | public IFacebookApiBuilder UseHttpClientHandler(HttpClientHandler handler) 88 | { 89 | handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; 90 | _httpHandler = handler; 91 | return this; 92 | } 93 | 94 | public IFacebookApiBuilder SetUser(UserSessionData user) 95 | { 96 | _user = user; 97 | return this; 98 | } 99 | 100 | public IFacebookApiBuilder SetRequestDelay(IRequestDelay delay) 101 | { 102 | if (delay == null) 103 | delay = RequestDelay.Empty(); 104 | _delay = delay; 105 | return this; 106 | } 107 | 108 | public IFacebookApiBuilder SetDevice(AndroidDevice androidDevice) 109 | { 110 | _device = androidDevice; 111 | return this; 112 | } 113 | 114 | public IFacebookApiBuilder SetSessionHandler(ISessionHandler sessionHandler) 115 | { 116 | _sessionHandler = sessionHandler; 117 | return this; 118 | } 119 | 120 | public static IFacebookApiBuilder CreateBuilder() 121 | { 122 | return new FacebookApiBuilder(); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Builder/IFacebookApiBuilder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.SessionHandlers; 10 | using FacebookApiSharp.Logger; 11 | using System.Net.Http; 12 | 13 | namespace FacebookApiSharp.API.Builder 14 | { 15 | public interface IFacebookApiBuilder 16 | { 17 | IFacebookApi Build(); 18 | 19 | IFacebookApiBuilder UseLogger(IFacebookLogger logger); 20 | 21 | IFacebookApiBuilder UseHttpClient(HttpClient httpClient); 22 | 23 | IFacebookApiBuilder UseHttpClientHandler(HttpClientHandler handler); 24 | 25 | IFacebookApiBuilder SetUser(UserSessionData user); 26 | 27 | IFacebookApiBuilder SetRequestDelay(IRequestDelay delay); 28 | 29 | IFacebookApiBuilder SetDevice(AndroidDevice androidDevice); 30 | 31 | IFacebookApiBuilder SetSessionHandler(ISessionHandler sessionHandler); 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/FacebookApiConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json.Linq; 8 | using System; 9 | 10 | namespace FacebookApiSharp.API 11 | { 12 | public static class FacebookApiConstants 13 | { 14 | public const string FACEBOOK_API_VERSION = "479.0.0.42.89"; 15 | public const string FACEBOOK_APP_VERSION = "636608107"; 16 | public const string FACEBOOK_ACCESS_TOKEN = "350685531728|62f8ce9f74b12f84c123cc23437a4a32"; 17 | public const string FACEBOOK_API_KEY = "882a8490361da98702bf97a021ddc14d"; 18 | public const string FACEBOOK_BLOKS_VERSION = "fcb188fb4c97a862b85d875824832dd3e42ead2a17102661b4bed0825f260514"; 19 | public const string FACEBOOK_STYLES_ID = "800cb86569d1fc1615bd1576caae8172"; 20 | 21 | 22 | //X-FB-Connection-Quality: EXCELLENT 23 | //X-FB-SIM-HNI: 43235 24 | //X-FB-Net-HNI: 43211 25 | //X-FB-Connection-Type: unknown 26 | //User-Agent: [FBAN/FB4A;FBAV/355.0.0.21.108;FBBV/352948159;FBDM/{density=2.75,width=1080,height=2111};FBLC/en_US;FBRV/0;FBCR/IR-MCI;FBMF/Xiaomi;FBBD/Redmi;FBPN/com.facebook.katana;FBDV/M2007J22G;FBSV/11;FBBK/1;FBOP/1;FBCA/arm64-v8a:;] 27 | //Host: graph.facebook.com 28 | //Content-Type: application/x-www-form-urlencoded 29 | //X-Tigon-Is-Retry: False 30 | //x-fb-device-group: 7864 31 | //X-FB-Friendly-Name: suggestedLanguages 32 | //X-FB-Request-Analytics-Tags: unknown 33 | //Accept-Encoding: gzip, deflate 34 | //X-FB-HTTP-Engine: Liger 35 | //X-FB-Client-IP: True 36 | //X-FB-Server-Cluster: True 37 | public const string HEADER_FB_CONNECTION_QUALITY = "X-FB-Connection-Quality"; // EXCELLENT 38 | public const string HEADER_FB_SIM_HNI = "X-FB-SIM-HNI"; 39 | public const string HEADER_FB_NET_HNI = "X-FB-Net-HNI"; 40 | public const string HEADER_FB_ZERO_STATE = "X-ZERO-STATE"; 41 | public const string HEADER_FB_CONNECTION_TYPE = "X-FB-Connection-Type"; 42 | public const string HEADER_FB_DEVICE_GROUP = "x-fb-device-group"; 43 | public const string HEADER_FB_CONNECTION_TOKEN = "x-fb-connection-token"; 44 | public const string HEADER_FB_RMD = "x-fb-rmd"; 45 | public const string HEADER_FB_FRIENDLY_NAME = "X-FB-Friendly-Name"; 46 | public const string HEADER_FB_REQUEST_ANALYTICS_TAGS = "X-FB-Request-Analytics-Tags"; 47 | public const string HEADER_FB_PRIVACY_CONTEXT = "X-FB-Privacy-Context"; 48 | public const string HEADER_FB_HTTP_ENGINE = "X-FB-HTTP-Engine"; 49 | public const string HEADER_FB_CLIENT_IP = "X-FB-Client-IP"; 50 | public const string HEADER_FB_SERVER_CLUSTER = "X-FB-Server-Cluster"; 51 | public const string HEADER_X_IG_TIGON_RETRY = "X-Tigon-Is-Retry"; 52 | public const string HEADER_USER_AGENT = "User-Agent"; 53 | public const string HEADER_ACCEPT_ENCODING = "Accept-Encoding"; 54 | public const string HEADER_ACCEPT_LANGUAGE = "Accept-Language"; 55 | public const string HEADER_AUTHORIZATION = "Authorization"; 56 | public const string HEADER_PRIORITY = "Priority"; 57 | 58 | 59 | 60 | public const string USER_AGENT_DEFAULT = "[FBAN/FB4A;FBAV/479.0.0.42.89;FBBV/636608107;FBDM/{density=2.75,width=1080,height=2111};FBLC/en_US;FBRV/0;FBCR/IR-MCI;FBMF/Xiaomi;FBBD/Redmi;FBPN/com.facebook.katana;FBDV/M2007J22G;FBSV/12;FBOP/1;FBCA/arm64-v8a:;]"; 61 | 62 | public const string HOST = "Host"; 63 | public const string HOST_URI = "graph.facebook.com"; 64 | public const string ACCEPT_ENCODING2 = "gzip, deflate"; 65 | 66 | public const string ACCEPT_ENCODING = "gzip, deflate, sdch"; 67 | public const string FACEBOOK_URL = "https://graph.facebook.com"; 68 | public const string FACEBOOK_WITHOUT_URL = "https://facebook.com"; 69 | public const string B_FACEBOOK_URL = "https://b-graph.facebook.com"; 70 | public static readonly Uri BaseFacebookUri = new Uri(FACEBOOK_URL); 71 | 72 | 73 | 74 | public static readonly JArray SupportedCapabalities = new JArray 75 | { 76 | new JObject 77 | { 78 | {"name","multiplane"}, 79 | {"value","multiplane_disabled"} 80 | }, 81 | new JObject 82 | { 83 | {"name","world_tracker"}, 84 | {"value","world_tracker_enabled"} 85 | }, 86 | new JObject 87 | { 88 | {"name","xray"}, 89 | {"value","xray_disabled"} 90 | }, 91 | new JObject 92 | { 93 | {"name","half_float_render_pass"}, 94 | {"value","half_float_render_pass_enabled"} 95 | }, 96 | new JObject 97 | { 98 | {"name","multiple_render_targets"}, 99 | {"value","multiple_render_targets_enabled"} 100 | }, 101 | new JObject 102 | { 103 | {"name","vertex_texture_fetch"}, 104 | {"value","vertex_texture_fetch_enabled"} 105 | }, 106 | new JObject 107 | { 108 | {"name","body_tracking"}, 109 | {"value","body_tracking_disabled"} 110 | }, 111 | new JObject 112 | { 113 | {"name","gyroscope"}, 114 | {"value","gyroscope_enabled"} 115 | }, 116 | new JObject 117 | { 118 | {"name","geoanchor"}, 119 | {"value","geoanchor_disabled"} 120 | }, 121 | new JObject 122 | { 123 | {"name","scene_depth"}, 124 | {"value","scene_depth_disabled"} 125 | }, 126 | new JObject 127 | { 128 | {"name","segmentation"}, 129 | {"value","segmentation_enabled"} 130 | }, 131 | new JObject 132 | { 133 | {"name","hand_tracking"}, 134 | {"value","hand_tracking_enabled"} 135 | }, 136 | new JObject 137 | { 138 | {"name","real_scale_estimation"}, 139 | {"value","real_scale_estimation_disabled"} 140 | }, 141 | new JObject 142 | { 143 | {"name","hair_segmentation"}, 144 | {"value","hair_segmentation_disabled"} 145 | }, 146 | new JObject 147 | { 148 | {"name","depth_shader_read"}, 149 | {"value","depth_shader_read_enabled"} 150 | }, 151 | new JObject 152 | { 153 | {"name","etc2_compression"}, 154 | {"value","compression"} 155 | }, 156 | new JObject 157 | { 158 | {"name","face_tracker_version"}, 159 | {"value","0"} 160 | }, 161 | }; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/IFacebookApi.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.Models; 10 | using FacebookApiSharp.Classes.Responses; 11 | using FacebookApiSharp.Classes.SessionHandlers; 12 | using FacebookApiSharp.Enums; 13 | using System.Collections.Generic; 14 | using System.Threading.Tasks; 15 | using FacebookApiSharp.API.Processors; 16 | 17 | namespace FacebookApiSharp.API 18 | { 19 | public interface IFacebookApi 20 | { 21 | Task> SendLoginFlowsAsync(); 22 | Task> LoginAsync(bool secondTime = false); 23 | Task> SendAfterLoginFlowsAsync(); 24 | Task> GetNetworkInterfaceAsync(); 25 | Task> GetPersistentComponentsAsync(); 26 | Task> GetLoginDataBatchAsync(); 27 | Task> GetLoginApprovalsKeysAsync(); 28 | Task> GetPasswordEncrytionKeyAsync(); 29 | 30 | ISessionHandler SessionHandler { get; } 31 | IMessagingProcessor MessagingProcessor { get; } 32 | IAccountProcessor AccountProcessor { get; } 33 | IUserProcessor UserProcessor { get; } 34 | IMediaProcessor MediaProcessor { get; } 35 | string SimCountry { get; set; } 36 | string NetworkCountry { get; set; } 37 | string ClientCountryCode { get; set; } 38 | string AppLocale { get; set; } 39 | string DeviceLocale { get; set; } 40 | string AcceptLanguage { get; set; } 41 | bool IsUserAuthenticated { get; } 42 | UserSessionData GetLoggedUser(); 43 | AndroidDevice GetCurrentDevice(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Processors/IAccounProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.Models; 10 | using FacebookApiSharp.Classes.Responses; 11 | using FacebookApiSharp.Classes.SessionHandlers; 12 | using FacebookApiSharp.Converters; 13 | using FacebookApiSharp.Enums; 14 | using FacebookApiSharp.Helpers; 15 | using FacebookApiSharp.Logger; 16 | using Newtonsoft.Json; 17 | using Newtonsoft.Json.Linq; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Diagnostics; 21 | using System.IO; 22 | using System.Linq; 23 | using System.Net; 24 | using System.Net.Http; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | namespace FacebookApiSharp.API.Processors 29 | { 30 | public interface IAccountProcessor 31 | { 32 | //Task> GetBookmarksQueryAsync(); 33 | 34 | //Task> GetSettingsFrameworkAsync(); 35 | 36 | //Task> GetNotificationsSettingsAsync(); 37 | 38 | //Task> DisableNotificationsFor8HoursAsync(); 39 | Task> GetLoginSessionsAsync(PaginationParameters pagination); 40 | Task> LogoutSessionAsync(string sessionId); 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Processors/IMediaProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.Models; 10 | using FacebookApiSharp.Classes.Responses; 11 | using FacebookApiSharp.Classes.SessionHandlers; 12 | using FacebookApiSharp.Converters; 13 | using FacebookApiSharp.Enums; 14 | using FacebookApiSharp.Helpers; 15 | using FacebookApiSharp.Logger; 16 | using Newtonsoft.Json; 17 | using Newtonsoft.Json.Linq; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Diagnostics; 21 | using System.IO; 22 | using System.Linq; 23 | using System.Net; 24 | using System.Net.Http; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | namespace FacebookApiSharp.API.Processors 29 | { 30 | public interface IMediaProcessor 31 | { 32 | Task> CommentMediaAsync(string feedbackId, string text, params string[] mentions); 33 | Task> DisableCommentsAsync(string postId, string id); 34 | Task> MakeNewPostAsync(string caption, bool disableComments); 35 | Task> UploadPhotoAsync(string caption, byte[] imageBytes, bool disableComments); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Processors/IMessagingProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | using FacebookApiSharp.Classes; 7 | using FacebookApiSharp.Classes.DeviceInfo; 8 | using FacebookApiSharp.Classes.Models; 9 | using FacebookApiSharp.Classes.Responses; 10 | using FacebookApiSharp.Classes.SessionHandlers; 11 | using FacebookApiSharp.Converters; 12 | using FacebookApiSharp.Enums; 13 | using FacebookApiSharp.Helpers; 14 | using FacebookApiSharp.Logger; 15 | using Newtonsoft.Json; 16 | using Newtonsoft.Json.Linq; 17 | using System; 18 | using System.Collections.Generic; 19 | using System.Diagnostics; 20 | using System.IO; 21 | using System.Linq; 22 | using System.Net; 23 | using System.Net.Http; 24 | using System.Text; 25 | using System.Threading.Tasks; 26 | 27 | namespace FacebookApiSharp.API.Processors 28 | { 29 | public interface IMessagingProcessor 30 | { 31 | Task> SendDirectMessageAsync(string userId, string message); 32 | Task> GetDirectInboxFriendsAsync(); 33 | Task> GetDirectInboxTopFriendsAsync(); 34 | Task> GetDirectInboxRecentltyActiveFriendsAsync(); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Processors/IUserProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.Models; 10 | using FacebookApiSharp.Classes.Responses; 11 | using FacebookApiSharp.Classes.SessionHandlers; 12 | using FacebookApiSharp.Converters; 13 | using FacebookApiSharp.Enums; 14 | using FacebookApiSharp.Helpers; 15 | using FacebookApiSharp.Logger; 16 | using Newtonsoft.Json; 17 | using Newtonsoft.Json.Linq; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Diagnostics; 21 | using System.IO; 22 | using System.Linq; 23 | using System.Net; 24 | using System.Net.Http; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | namespace FacebookApiSharp.API.Processors 29 | { 30 | public interface IUserProcessor 31 | { 32 | Task>> SearchAsync(string query, 33 | PaginationParameters pagination); 34 | Task> GetFriendsAsync(PaginationParameters pagination); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/API/Processors/MessagingProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using FacebookApiSharp.Classes.Models; 10 | using FacebookApiSharp.Classes.Responses; 11 | using FacebookApiSharp.Classes.SessionHandlers; 12 | using FacebookApiSharp.Converters; 13 | using FacebookApiSharp.Enums; 14 | using FacebookApiSharp.Helpers; 15 | using FacebookApiSharp.Logger; 16 | using Newtonsoft.Json; 17 | using Newtonsoft.Json.Linq; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Diagnostics; 21 | using System.IO; 22 | using System.Linq; 23 | using System.Net; 24 | using System.Net.Http; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | namespace FacebookApiSharp.API.Processors 29 | { 30 | class MessagingProcessor : IMessagingProcessor 31 | { 32 | private readonly HttpHelper _httpHelper; 33 | private readonly UserSessionData User; 34 | private readonly IFacebookLogger _logger; 35 | private readonly AndroidDevice _deviceInfo; 36 | private readonly IHttpRequestProcessor _httpRequestProcessor; 37 | private readonly FacebookApi _facebookApi; 38 | public MessagingProcessor(AndroidDevice deviceInfo, 39 | UserSessionData user, 40 | IHttpRequestProcessor httpRequestProcessor, 41 | IFacebookLogger logger, 42 | FacebookApi facebookApi, 43 | HttpHelper httpHelper) 44 | { 45 | _deviceInfo = deviceInfo; 46 | _facebookApi = facebookApi; 47 | User = user; 48 | _logger = logger; 49 | _httpHelper = httpHelper; 50 | _httpRequestProcessor = httpRequestProcessor; 51 | } 52 | 53 | 54 | 55 | public async Task> SendDirectMessageAsync(string userId, string message) 56 | { 57 | string responseContent = null; 58 | 59 | try 60 | { 61 | var instaUri = UriCreator.GetGraphQLUri(); 62 | var token = ExtensionsHelper.GetThreadToken(); 63 | 64 | //client_doc_id=192413211313323631505026260873& 65 | //method=post& 66 | //locale=en_US& 67 | //pretty=false& 68 | //format=json& 69 | 70 | //&fb_api_req_friendly_name=MessagingInBlueSendMessageMutation& 71 | //fb_api_caller_class=graphservice& 72 | //fb_api_analytics_tags=["nav_attribution_id={\"0\":{\"bookmark_id\":\"391724414624676\",\"session\":\"53b17\",\"subsession\":1,\"timestamp\":\"1646712153.760\",\"tap_point\":\"tap_search_bar\",\"most_recent_tap_point\":\"foreground\",\"bookmark_type_name\":null,\"fallback\":false},\"1\":{\"bookmark_id\":\"4748854339\",\"session\":\"6fca9\",\"subsession\":1,\"timestamp\":\"1646712143.488\",\"tap_point\":\"cold_start\",\"most_recent_tap_point\":\"cold_start\",\"bookmark_type_name\":null,\"fallback\":false,\"badging\":{\"badge_count\":0,\"badge_type\":\"num\"}}}","visitation_id=4748854339:6fca9:1:1646712143.488","GraphServices"] 73 | //&server_timestamps=true 74 | 75 | 76 | 77 | //"product_extras": { "product_type": "PROFILE" }, 78 | //"offline_message_id": "6906811681774978189", // thread token 79 | //"message_content_info": { 80 | // "text": "Hi", 81 | // "message_type": "TEXT" 82 | //}, 83 | var input = new JObject() 84 | { 85 | {"product_extras", new JObject 86 | { 87 | {"product_type", "PROFILE"} 88 | } 89 | }, 90 | {"offline_message_id", token}, 91 | {"message_content_info", new JObject 92 | { 93 | {"text", message}, 94 | {"message_type", "TEXT"}, 95 | } 96 | }, 97 | //"messaging_thread_id": "100076841659377",// user id taraf 98 | {"messaging_thread_id", userId}, 99 | //"logging_info": { 100 | // "mib_instance_id": "8603276787900485746", 101 | // "mib_hierarchy_data": "{\"0\":{\"class\":\"MibMainFragment\",\"module\":null,\"tap_point\":null},\"1\":{\"class\":\"MibMainActivity\",\"module\":null,\"tap_point\":null},\"2\":{\"class\":\"ProfileFragment\",\"module\":\"timeline\",\"tap_point\":null},\"3\":{\"class\":\"ImmersiveActivity\",\"module\":\"unknown\",\"tap_point\":null},\"4\":{\"class\":\"SearchResultsFragment\",\"module\":\"graph_search_results_page_blended\",\"tap_point\":null},\"5\":{\"class\":\"GraphSearchFragment\",\"module\":\"unknown\",\"tap_point\":null},\"6\":{\"class\":\"ImmersiveActivity\",\"module\":\"unknown\",\"tap_point\":null},\"7\":{\"class\":\"NewsFeedFragment\",\"module\":\"native_newsfeed\",\"tap_point\":null},\"8\":{\"class\":\"FeedFiltersFragment\",\"module\":\"native_newsfeed\",\"tap_point\":null},\"9\":{\"class\":\"FbChromeFragment\",\"module\":null,\"tap_point\":\"cold_start\"},\"10\":{\"class\":\"FbMainTabActivity\",\"module\":\"unknown\",\"tap_point\":null}}", 102 | // "mib_entry_point": "fb_profile:message_button", 103 | // "messaging_source": "source:profile" 104 | //}, 105 | {"logging_info", new JObject 106 | { 107 | //{"mib_instance_id", "8603276787900485746"}, 108 | {"mib_hierarchy_data", "{\"0\":{\"class\":\"MibMainFragment\",\"module\":null,\"tap_point\":null},\"1\":{\"class\":\"MibMainActivity\",\"module\":null,\"tap_point\":null},\"2\":{\"class\":\"ProfileFragment\",\"module\":\"timeline\",\"tap_point\":null},\"3\":{\"class\":\"ImmersiveActivity\",\"module\":\"unknown\",\"tap_point\":null},\"4\":{\"class\":\"SearchResultsFragment\",\"module\":\"graph_search_results_page_blended\",\"tap_point\":null},\"5\":{\"class\":\"GraphSearchFragment\",\"module\":\"unknown\",\"tap_point\":null},\"6\":{\"class\":\"ImmersiveActivity\",\"module\":\"unknown\",\"tap_point\":null},\"7\":{\"class\":\"NewsFeedFragment\",\"module\":\"native_newsfeed\",\"tap_point\":null},\"8\":{\"class\":\"FeedFiltersFragment\",\"module\":\"native_newsfeed\",\"tap_point\":null},\"9\":{\"class\":\"FbChromeFragment\",\"module\":null,\"tap_point\":\"cold_start\"},\"10\":{\"class\":\"FbMainTabActivity\",\"module\":\"unknown\",\"tap_point\":null}}"}, 109 | {"mib_entry_point", "fb_profile:message_button"}, 110 | {"messaging_source", "source:profile"}, 111 | } 112 | }, 113 | //"client_mutation_id": "fbd5c771-a462-48c9-a4f6-9410d166a821", // guid 114 | //"actor_id": "100034137818552" // usere khodet 115 | {"client_mutation_id", Guid.NewGuid().ToString()}, 116 | {"actor_id", User.LoggedInUser.UId.ToString()}, 117 | }; 118 | Debug.WriteLine(input.ToString(Formatting.Indented)); 119 | var variables = new JObject() 120 | { 121 | {"input", input}, 122 | {"profile_pic_size", 99}, 123 | {"large_preview_image_height", 750}, 124 | {"full_screen_image_width", 2048}, 125 | {"full_screen_image_height", 2048}, 126 | {"large_preview_image_width", 750}, 127 | {"nt_context", new JObject 128 | { 129 | {"using_white_navbar", true}, 130 | {"styles_id", FacebookApiConstants.FACEBOOK_STYLES_ID}, 131 | {"pixel_ratio", 3}, 132 | {"bloks_version", FacebookApiConstants.FACEBOOK_BLOKS_VERSION}, 133 | } 134 | }, 135 | }; 136 | var data = new Dictionary 137 | { 138 | {"client_doc_id", "192413211313323631505026260873"}, 139 | {"method", "post"}, 140 | {"locale", _facebookApi.AppLocale}, 141 | {"pretty", "false"}, 142 | {"format", "json"}, 143 | {"variables", variables.ToString(Formatting.None)}, 144 | {"fb_api_req_friendly_name", "MessagingInBlueSendMessageMutation"}, 145 | {"fb_api_caller_class", "graphservice"}, 146 | {"fb_api_analytics_tags", "[\"GraphServices\"]"}, 147 | {"server_timestamps", "true"}, 148 | {"access_token", FacebookApiConstants.FACEBOOK_ACCESS_TOKEN}, 149 | }; 150 | var request = _httpHelper.GetDefaultRequest(HttpMethod.Post, 151 | instaUri, _deviceInfo, data); 152 | request.Headers.AddHeader(FacebookApiConstants.HEADER_FB_FRIENDLY_NAME, "MessagingInBlueSendMessageMutation", true); 153 | request.Headers.AddHeader(FacebookApiConstants.HEADER_FB_RMD, "cached=0;state=NO_MATCH", true); 154 | request.Headers.AddHeader(FacebookApiConstants.HEADER_PRIORITY, "u=3, i"); 155 | 156 | var response = await _httpRequestProcessor.SendAsync(request); 157 | var json = await response.Content.ReadAsStringAsync(); 158 | if (response.StatusCode != HttpStatusCode.OK) 159 | return Result.UnExpectedResponse(response, json); 160 | 161 | var validateCheckpoint = ExtensionsHelper.CheckpointCheck(response.Headers); 162 | if (validateCheckpoint.Item1) 163 | return Result.Fail(validateCheckpoint.Item2, 164 | ResponseType.CheckpointAccount, default(FacebookMessage)); 165 | 166 | responseContent = json; 167 | 168 | var obj = JsonConvert.DeserializeObject(json); 169 | 170 | return Result.Success(ObjectsConverter.Instance.GetDirectMessageConverter(obj).Convert()); 171 | } 172 | catch (HttpRequestException httpException) 173 | { 174 | _logger?.LogException(httpException); 175 | return Result.Fail(httpException, default(FacebookMessage), ResponseType.NetworkProblem); 176 | } 177 | catch (Exception exception) 178 | { 179 | _logger?.LogException(exception); 180 | return Result.Fail(exception, responseContent); 181 | } 182 | } 183 | 184 | public async Task> GetDirectInboxFriendsAsync() 185 | { 186 | //client_doc_id=157070121311310993102490765089& 187 | //method=post& 188 | //locale=en_US& 189 | //pretty=false& 190 | //format=json&variables={"page_size":7,"tile_size":220}& 191 | //fb_api_req_friendly_name=FriendsFacepilesQuery& 192 | //fb_api_caller_class=graphservice& 193 | //fb_api_analytics_tags=["GraphServices"]& 194 | //server_timestamps=true 195 | return await _facebookApi.SendRequestAsync 196 | ("157070121311310993102490765089", 197 | "post", 198 | "FriendsFacepilesQuery", 199 | "[\"GraphServices\"]", 200 | "{\"page_size\":7,\"tile_size\":220}", 201 | new FacebookInboxFriendsConverter()); 202 | } 203 | 204 | public async Task> GetDirectInboxTopFriendsAsync() 205 | { 206 | //client_doc_id=750929114295349742161526918& 207 | //method=post& 208 | //locale=en_US& 209 | //pretty=false& 210 | //format=json& 211 | //variables={"tile_size":240}& 212 | //fb_api_req_friendly_name=MIBTopFriendsQuery& 213 | //fb_api_caller_class=graphservice& 214 | //fb_api_analytics_tags=["GraphServices"]& 215 | //server_timestamps=true 216 | return await _facebookApi.SendRequestAsync 217 | ("750929114295349742161526918", 218 | "post", 219 | "MIBTopFriendsQuery", 220 | "[\"GraphServices\"]", 221 | "{\"tile_size\":240}", 222 | new FacebookInboxTopFriendsConverter()); 223 | } 224 | 225 | public async Task> GetDirectInboxRecentltyActiveFriendsAsync() 226 | { 227 | //client_doc_id=115333238017266656933682149605& 228 | //method=post& 229 | //locale=en_US& 230 | //pretty=false& 231 | //format=json& 232 | //variables={"count":20,"tile_size":165}& 233 | //fb_api_req_friendly_name=ActiveNowQueryWithRecentlyActive& 234 | //fb_api_caller_class=graphservice& 235 | //fb_api_analytics_tags=["GraphServices"]& 236 | //server_timestamps=true 237 | return await _facebookApi.SendRequestAsync 238 | ("115333238017266656933682149605", 239 | "post", 240 | "ActiveNowQueryWithRecentlyActive", 241 | "[\"GraphServices\"]", 242 | "{\"count\":20,\"tile_size\":165}", 243 | new FacebookInboxFriendsConverter()); 244 | } 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/DeviceInfo/AndroidDevice.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | 9 | namespace FacebookApiSharp.Classes.DeviceInfo 10 | { 11 | [Serializable] 12 | public class AndroidDevice 13 | { 14 | public Guid PhoneGuid { get; set; } 15 | public Guid DeviceGuid { get; set; } 16 | public Guid GoogleAdId { get; set; } = Guid.NewGuid(); 17 | public Guid RankToken { get; set; } = Guid.NewGuid(); 18 | public Guid AdId { get; set; } = Guid.NewGuid(); 19 | public Guid PigeonSessionId { get; set; } = Guid.NewGuid(); 20 | public Guid PushDeviceGuid { get; set; } = Guid.NewGuid(); 21 | public Guid FamilyDeviceGuid { get; set; } 22 | 23 | public AndroidVersion AndroidVer { get; set; } = AndroidVersion.GetRandomAndriodVersion(); 24 | 25 | public string AndroidBoardName { get; set; } 26 | public string AndroidBootloader { get; set; } 27 | public string DeviceBrand { get; set; } 28 | public string DeviceId { get; set; } 29 | public string DeviceModel { get; set; } 30 | public string DeviceModelBoot { get; set; } = "qcom"; 31 | public string DeviceModelIdentifier { get; set; } 32 | public string FirmwareBrand { get; set; } 33 | public string FirmwareFingerprint { get; set; } 34 | public string FirmwareTags { get; set; } 35 | public string FirmwareType { get; set; } 36 | public string HardwareManufacturer { get; set; } 37 | public string HardwareModel { get; set; } 38 | public string Resolution { get; set; } = "1080x1812"; 39 | public string Dpi { get; set; } = "480dpi"; 40 | 41 | 42 | 43 | public const string CPU_ABI = "arm64-v8a:"; 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/DeviceInfo/AndroidDeviceGenerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | 11 | namespace FacebookApiSharp.Classes.DeviceInfo 12 | { 13 | public class AndroidDeviceGenerator 14 | { 15 | private static readonly List DevicesNames = new List 16 | { 17 | AndroidDevices.HONOR_8LITE, 18 | AndroidDevices.XIAOMI_MI_4W, 19 | AndroidDevices.XIAOMI_HM_1SW, 20 | AndroidDevices.HTC_ONE_PLUS 21 | }; 22 | 23 | public static Dictionary AndroidAndroidDeviceSets = new Dictionary 24 | { 25 | { 26 | AndroidDevices.HONOR_8LITE, 27 | new AndroidDevice 28 | { 29 | AndroidBoardName = "HONOR", 30 | DeviceBrand = "HUAWEI", 31 | HardwareManufacturer = "HUAWEI", 32 | DeviceModel = "PRA-LA1", 33 | DeviceModelIdentifier = "PRA-LA1", 34 | FirmwareBrand = "HWPRA-H", 35 | HardwareModel = "hi6250", 36 | DeviceGuid = Guid.NewGuid(), 37 | PhoneGuid = Guid.NewGuid(), 38 | Resolution = "1080x1812", 39 | Dpi = "480dpi", 40 | } 41 | }, 42 | { 43 | AndroidDevices.XIAOMI_MI_4W, 44 | new AndroidDevice 45 | { 46 | AndroidBoardName = "MI", 47 | DeviceBrand = "Xiaomi", 48 | HardwareManufacturer = "Xiaomi", 49 | DeviceModel = "MI-4W", 50 | DeviceModelIdentifier = "4W", 51 | FirmwareBrand = "4W", 52 | HardwareModel = "cancro", 53 | DeviceGuid = Guid.NewGuid(), 54 | PhoneGuid = Guid.NewGuid(), 55 | Resolution = "1080x1920", 56 | Dpi = "480dpi", 57 | } 58 | }, 59 | { 60 | AndroidDevices.XIAOMI_HM_1SW, 61 | new AndroidDevice 62 | { 63 | AndroidBoardName = "HM", 64 | DeviceBrand = "Xiaomi", 65 | HardwareManufacturer = "Xiaomi", 66 | DeviceModel = "HM-1SW", 67 | DeviceModelIdentifier = "1SW", 68 | FirmwareBrand = "1SW", 69 | HardwareModel = "armani", 70 | DeviceGuid = Guid.NewGuid(), 71 | PhoneGuid = Guid.NewGuid(), 72 | Resolution = "720x1280", 73 | Dpi = "320dpi", 74 | } 75 | }, 76 | { 77 | AndroidDevices.HTC_ONE_PLUS, 78 | new AndroidDevice 79 | { 80 | AndroidBoardName = "One", 81 | DeviceBrand = "Htc", 82 | HardwareManufacturer = "Htc", 83 | DeviceModel = "One-Plus", 84 | DeviceModelIdentifier = "Plus", 85 | FirmwareBrand = "Plus", 86 | HardwareModel = "A3010", 87 | DeviceGuid = Guid.NewGuid(), 88 | PhoneGuid = Guid.NewGuid(), 89 | Resolution = "1080x1920", 90 | Dpi = "380dpi", 91 | } 92 | } 93 | }; 94 | 95 | static readonly Random Rnd = new Random(); 96 | public static AndroidDevice GetRandomAndroidDevice() 97 | { 98 | var randomDeviceIndex = Rnd.Next(0, DevicesNames.Count); 99 | var device = AndroidAndroidDeviceSets.ElementAt(randomDeviceIndex).Value; 100 | device.FamilyDeviceGuid = device.PhoneGuid = Guid.NewGuid(); 101 | device.DeviceGuid = Guid.NewGuid(); 102 | device.PigeonSessionId = Guid.NewGuid(); 103 | device.PushDeviceGuid = Guid.NewGuid(); 104 | 105 | return device; 106 | } 107 | 108 | public static AndroidDevice GetByName(string name) 109 | { 110 | return AndroidAndroidDeviceSets[name]; 111 | } 112 | 113 | public static AndroidDevice GetById(string deviceId) 114 | { 115 | return (from androidAndroidDeviceSet in AndroidAndroidDeviceSets 116 | where androidAndroidDeviceSet.Value.DeviceId == deviceId 117 | select androidAndroidDeviceSet.Value).FirstOrDefault(); 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/DeviceInfo/AndroidDevices.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | namespace FacebookApiSharp.Classes.DeviceInfo 8 | { 9 | public class AndroidDevices 10 | { 11 | public const string HONOR_8LITE = "honor-8lite"; 12 | public const string XIAOMI_MI_4W = "xiaomi-mi-4w"; 13 | public const string XIAOMI_HM_1SW = "xiaomi-hm-1sw"; 14 | public const string HTC_ONE_PLUS = "htc-one-plus"; 15 | } 16 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/DeviceInfo/AndroidVersion.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Linq; 9 | 10 | namespace FacebookApiSharp.Classes.DeviceInfo 11 | { 12 | [Serializable] 13 | public class AndroidVersion 14 | { 15 | public string Codename { get; set; } 16 | public string VersionNumber { get; set; } 17 | public string APILevel { get; set; } 18 | 19 | public static AndroidVersion FromString(string versionString) 20 | { 21 | var version = new Version(versionString); 22 | foreach (var androidVersion in AndroidVersionList.GetVersionList().AndroidVersions()) 23 | if (version.CompareTo(new Version(androidVersion.VersionNumber)) == 0 || 24 | version.CompareTo(new Version(androidVersion.VersionNumber)) > 0 && 25 | androidVersion != AndroidVersionList.GetVersionList().AndroidVersions().Last() && 26 | version.CompareTo(new Version(AndroidVersionList.GetVersionList().AndroidVersions()[AndroidVersionList.GetVersionList().AndroidVersions().IndexOf(androidVersion) + 1] 27 | .VersionNumber)) < 0) 28 | return androidVersion; 29 | return null; 30 | } 31 | 32 | static Random Rnd = new Random(); 33 | private static AndroidVersion LastAndriodVersion = AndroidVersionList.GetVersionList().AndroidVersions()[AndroidVersionList.GetVersionList().AndroidVersions().Count - 2]; 34 | public static AndroidVersion GetRandomAndriodVersion() 35 | { 36 | TryLabel: 37 | var randomDeviceIndex = Rnd.Next(0, AndroidVersionList.GetVersionList().AndroidVersions().Count); 38 | var androidVersion = AndroidVersionList.GetVersionList().AndroidVersions().ElementAt(randomDeviceIndex); 39 | if (LastAndriodVersion != null) 40 | if (androidVersion.APILevel == LastAndriodVersion.APILevel) 41 | goto TryLabel; 42 | LastAndriodVersion = androidVersion; 43 | return androidVersion; 44 | } 45 | public static AndroidVersion GetAndroidVersion(string apiLevel) 46 | { 47 | if (string.IsNullOrEmpty(apiLevel)) return null; 48 | 49 | return AndroidVersionList.GetVersionList().AndroidVersions().FirstOrDefault(api => api.APILevel == apiLevel); 50 | } 51 | public static AndroidVersion GetAndroid9() 52 | { 53 | var androidVer = AndroidVersionList.GetVersionList().AndroidVersions().FirstOrDefault(api => api.VersionNumber == "9.0.0"); 54 | androidVer.VersionNumber = "9"; 55 | return androidVer; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/DeviceInfo/AndroidVersionList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System.Collections.Generic; 8 | 9 | namespace FacebookApiSharp.Classes.DeviceInfo 10 | { 11 | public class AndroidVersionList 12 | { 13 | public static AndroidVersionList GetVersionList() => new AndroidVersionList(); 14 | 15 | public List AndroidVersions() 16 | { 17 | return new List 18 | { 19 | new AndroidVersion 20 | { 21 | Codename = "Pie", 22 | VersionNumber = "9.0.0", 23 | APILevel = "28" 24 | }, 25 | new AndroidVersion 26 | { 27 | Codename = "Android 10", 28 | VersionNumber = "10.0.0", 29 | APILevel = "29" 30 | }, 31 | new AndroidVersion 32 | { 33 | Codename = "Android 11", 34 | VersionNumber = "11.0.0", 35 | APILevel = "30" 36 | } 37 | }; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/FacebookDataPageResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using Newtonsoft.Json; 10 | 11 | namespace FacebookApiSharp.Classes.Responses 12 | { 13 | public class FacebookDataPageResultList : List { } 14 | 15 | public class FacebookDataPageResult 16 | { 17 | [JsonProperty("label")] 18 | public string Label { get; set; } 19 | [JsonProperty("path")] 20 | public object[] Path { get; set; } 21 | [JsonProperty("data")] 22 | public Data Data { get; set; } 23 | [JsonProperty("extensions")] 24 | public FacebookPageResultExtensionsResponse Extensions { get; set; } 25 | } 26 | 27 | public class Data 28 | { 29 | [JsonProperty("logging_unit_id")] 30 | public string LoggingUnitId { get; set; } 31 | [JsonProperty("native_template_view")] 32 | public FacebookNativeTemplateView NativeTemplateView { get; set; } 33 | [JsonProperty("native_template_result_ids")] 34 | public string[] NativeTemplateResultIds { get; set; } 35 | } 36 | 37 | public class FacebookNativeTemplateView 38 | { 39 | [JsonProperty("logging_id")] 40 | public string LoggingId { get; set; } 41 | [JsonProperty("data_diff_item_id")] 42 | public string DataDiffItemId { get; set; } 43 | [JsonProperty("data_diff_content_id")] 44 | public string DataDiffContentId { get; set; } 45 | [JsonProperty("unique_id")] 46 | public string UniqueId { get; set; } 47 | [JsonProperty("native_template_bundles")] 48 | public FacebookNativeTemplateBundles[] NativeTemplateBundles { get; set; } 49 | } 50 | 51 | public class FacebookNativeTemplateBundles 52 | { 53 | [JsonProperty("nt_bundle_tree")] 54 | public string NtBundleTree { get; set; } 55 | [JsonProperty("nt_bundle_attributes")] 56 | public FacebookNtBundleAttributes[] NtBundleAttributes { get; set; } 57 | } 58 | 59 | public class FacebookNtBundleAttributes 60 | { 61 | [JsonProperty("__typename")] 62 | public string Typename { get; set; } 63 | [JsonProperty("name")] 64 | public string Name { get; set; } 65 | [JsonProperty("strong_id__")] 66 | public string StrongId { get; set; } 67 | [JsonProperty("story_value")] 68 | public FacebookStoryValue StoryValue { get; set; } 69 | } 70 | 71 | public class FacebookStoryValue 72 | { 73 | [JsonProperty("id")] 74 | public string Id { get; set; } 75 | [JsonProperty("cache_id")] 76 | public string CacheId { get; set; } 77 | [JsonProperty("creation_time")] 78 | public long CreationTime { get; set; } 79 | [JsonProperty("url")] 80 | public string Url { get; set; } 81 | [JsonProperty("actors")] 82 | public FacebookActorResponse[] Actors { get; set; } 83 | [JsonProperty("tracking")] 84 | public string Tracking { get; set; } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/HttpRequestProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using FacebookApiSharp.Helpers; 9 | using FacebookApiSharp.Logger; 10 | using System; 11 | using System.Net; 12 | using System.Net.Http; 13 | using System.Threading.Tasks; 14 | 15 | namespace FacebookApiSharp.Classes 16 | { 17 | internal class HttpRequestProcessor : IHttpRequestProcessor 18 | { 19 | private IRequestDelay _delay; 20 | private IFacebookLogger _logger; 21 | public IRequestDelay Delay { get { return _delay; } set { _delay = value; } } 22 | public HttpRequestProcessor(IRequestDelay delay, HttpClient httpClient, HttpClientHandler httpHandler, 23 | IFacebookLogger logger) 24 | { 25 | _delay = delay; 26 | Client = httpClient; 27 | HttpHandler = httpHandler; 28 | _logger = logger; 29 | } 30 | 31 | public HttpClientHandler HttpHandler { get; set; } 32 | public HttpClient Client { get; set; } 33 | public void SetHttpClientHandler(HttpClientHandler handler) 34 | { 35 | handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; 36 | 37 | HttpHandler = handler; 38 | Client = new HttpClient(handler) { BaseAddress = new Uri(FacebookApiConstants.FACEBOOK_URL) }; 39 | } 40 | 41 | public async Task SendAsync(HttpRequestMessage requestMessage, bool keepAlive = false) 42 | { 43 | await AppendOtherHeaders(requestMessage, keepAlive); 44 | LogHttpRequest(requestMessage); 45 | if (_delay.Exist) 46 | await Task.Delay(_delay.Value); 47 | var response = await Client.SendAsync(requestMessage); 48 | LogHttpResponse(response); 49 | return response; 50 | } 51 | 52 | public async Task GetAsync(Uri requestUri, bool keepAlive = false) 53 | { 54 | await AppendOtherHeaders(null, keepAlive); 55 | _logger?.LogRequest(requestUri); 56 | if (_delay.Exist) 57 | await Task.Delay(_delay.Value); 58 | var response = await Client.GetAsync(requestUri); 59 | LogHttpResponse(response); 60 | return response; 61 | } 62 | 63 | public async Task SendAsync(HttpRequestMessage requestMessage, 64 | HttpCompletionOption completionOption, bool keepAlive = false) 65 | { 66 | await AppendOtherHeaders(requestMessage, keepAlive); 67 | LogHttpRequest(requestMessage); 68 | if (_delay.Exist) 69 | await Task.Delay(_delay.Value); 70 | var response = await Client.SendAsync(requestMessage, completionOption); 71 | LogHttpResponse(response); 72 | return response; 73 | } 74 | 75 | public async Task SendAndGetJsonAsync(HttpRequestMessage requestMessage, 76 | HttpCompletionOption completionOption, bool keepAlive = false) 77 | { 78 | await AppendOtherHeaders(requestMessage, keepAlive); 79 | LogHttpRequest(requestMessage); 80 | if (_delay.Exist) 81 | await Task.Delay(_delay.Value); 82 | var response = await Client.SendAsync(requestMessage, completionOption); 83 | LogHttpResponse(response); 84 | return await response.Content.ReadAsStringAsync(); 85 | } 86 | 87 | public async Task GeJsonAsync(Uri requestUri, bool keepAlive = false) 88 | { 89 | await AppendOtherHeaders(null, keepAlive); 90 | _logger?.LogRequest(requestUri); 91 | if (_delay.Exist) 92 | await Task.Delay(_delay.Value); 93 | var response = await Client.GetAsync(requestUri); 94 | LogHttpResponse(response); 95 | return await response.Content.ReadAsStringAsync(); 96 | } 97 | 98 | private void LogHttpRequest(HttpRequestMessage request) 99 | { 100 | _logger?.LogRequest(request); 101 | } 102 | 103 | private void LogHttpResponse(HttpResponseMessage request) 104 | { 105 | _logger?.LogResponse(request); 106 | } 107 | 108 | async Task AppendOtherHeaders(HttpRequestMessage request, bool keepAlive = false) 109 | { 110 | var currentCulture = HttpHelper.GetCurrentCulture(); 111 | System.Globalization.CultureInfo.CurrentCulture = HttpHelper.EnglishCulture; 112 | Client.DefaultRequestHeaders.ConnectionClose = keepAlive; 113 | if (request != null) 114 | { 115 | request.Headers.ConnectionClose = keepAlive; 116 | if (request.Content != null) 117 | { 118 | if (request.Content.Headers.ContentType != null) 119 | request.Content.Headers.ContentType.CharSet = "UTF-8"; 120 | if(!request.RequestUri.ToString().Contains("me/photos")) 121 | request.Content.Headers.ContentLength = request.Content.ReadAsStringAsync().GetAwaiter().GetResult()?.Length; 122 | } 123 | } 124 | System.Globalization.CultureInfo.CurrentCulture = currentCulture; 125 | await Task.Delay(1).ConfigureAwait(false); // lets force compiler to wait for AppendOtherHeaders 126 | } 127 | 128 | static bool WasntIndexOf(string str1, string str2) => str1.IndexOf(str2, StringComparison.OrdinalIgnoreCase) == -1; 129 | 130 | #region IDisposable Implementations 131 | 132 | public void Dispose() 133 | { 134 | Dispose(disposing: true); 135 | GC.SuppressFinalize(this); 136 | } 137 | 138 | protected virtual void Dispose(bool disposing) 139 | { 140 | if (disposing) 141 | { 142 | Client?.CancelPendingRequests(); 143 | Client?.Dispose(); 144 | HttpHandler?.Dispose(); 145 | } 146 | 147 | _delay = null; 148 | _logger = null; 149 | HttpHandler = null; 150 | Client = null; 151 | } 152 | 153 | #endregion 154 | } 155 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/IHttpRequestProcessor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | 8 | using System; 9 | using System.Net.Http; 10 | using System.Threading.Tasks; 11 | 12 | namespace FacebookApiSharp.Classes 13 | { 14 | public interface IHttpRequestProcessor : IDisposable 15 | { 16 | HttpClientHandler HttpHandler { get; set; } 17 | HttpClient Client { get; } 18 | void SetHttpClientHandler(HttpClientHandler handler); 19 | Task SendAsync(HttpRequestMessage requestMessage, bool keepAlive = false); 20 | Task GetAsync(Uri requestUri, bool keepAlive = false); 21 | Task SendAsync(HttpRequestMessage requestMessage, HttpCompletionOption completionOption, bool keepAlive = false); 22 | Task SendAndGetJsonAsync(HttpRequestMessage requestMessage, HttpCompletionOption completionOption, bool keepAlive = false); 23 | Task GeJsonAsync(Uri requestUri, bool keepAlive = false); 24 | IRequestDelay Delay { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/IRequestDelay.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | 9 | namespace FacebookApiSharp.Classes 10 | { 11 | public interface IRequestDelay 12 | { 13 | TimeSpan Value { get; } 14 | bool Exist { get; } 15 | void Enable(); 16 | void Disable(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/IResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Classes 12 | { 13 | public interface IResult 14 | { 15 | bool Succeeded { get; } 16 | T Value { get; } 17 | ResultInfo Info { get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Models/FacebookFriends.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Responses; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes.Models 13 | { 14 | public class FacebookFriends 15 | { 16 | public int FriendRequestCount { get; set; } 17 | public FacebookPageInfoResponse PageInfo { get; set; } 18 | public List Users { get; set; } = new List(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Models/FacebookLoginSession.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System.Collections.Generic; 8 | using System.Net; 9 | 10 | namespace FacebookApiSharp.Classes.Models 11 | { 12 | public class FacebookLoginSession 13 | { 14 | public string SessionKey { get; set; } 15 | public long UId { get; set; } 16 | public string Secret { get; set; } 17 | public string AccessToken { get; set; } 18 | public string AnalyticsClaim { get; set; } 19 | public bool Confirmed { get; set; } 20 | public string Identifier { get; set; } 21 | public string UserStorageKey { get; set; } 22 | public List RawCookies { get; internal set; } = new List(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Models/FacebookMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Responses; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes.Models 13 | { 14 | public class FacebookMessage 15 | { 16 | public string Typename { get; set; } 17 | public string MessageId { get; set; } 18 | public string OfflineThreadingId { get; set; } 19 | public string TimestampPrecise { get; set; } 20 | public string Snippet { get; set; } 21 | public string UnsentTimestampPrecise { get; set; } 22 | public FacebookActorResponse MessageSender { get; set; } 23 | public string Text { get; set; } 24 | public string Id { get; set; } 25 | public string[] TagsList { get; set; } 26 | public string StrongId { get; set; } 27 | public string ClientMutationId { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Models/Messaging/FacebookInboxFriends.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Classes.Models 12 | { 13 | public class FacebookInboxFriends 14 | { 15 | public string SelfUserId { get; set; } 16 | public int Count { get; set; } 17 | public List Users { get; set; } = new List(); 18 | } 19 | public class FacebookInboxFriendsUser 20 | { 21 | public string Name { get; set; } 22 | public string ShortName { get; set; } 23 | public string ProfilePicture { get; set; } 24 | public string Id { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Models/Messaging/FacebookInboxTopFriends.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Classes.Models 12 | { 13 | public class FacebookInboxTopFriends 14 | { 15 | public string SelfUserId { get; set; } 16 | public int Count { get; set; } 17 | public List Users { get; set; } = new List(); 18 | } 19 | public class FacebookInboxTopFriendsUser : FacebookInboxFriendsUser 20 | { 21 | public string IsCurrentlyActive { get; set; } 22 | public long? LastActiveMessagesStatusTime { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/PaginationParameters.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System.Collections.Generic; 8 | 9 | namespace FacebookApiSharp 10 | { 11 | public class PaginationParameters 12 | { 13 | private PaginationParameters() 14 | { 15 | SessionId = System.Guid.NewGuid().ToString(); 16 | } 17 | public bool HasPreviousPage { get; set; } 18 | public string StartCursor { get; set; } = string.Empty; 19 | public string EndCursor { get; set; } = string.Empty; 20 | 21 | public string SessionId { get; set; } = string.Empty; 22 | public int MaximumPagesToLoad { get; set; } 23 | public int PagesLoaded { get; set; } = 1; 24 | 25 | public static PaginationParameters Empty => MaxPagesToLoad(int.MaxValue); 26 | 27 | public static PaginationParameters MaxPagesToLoad(int maxPagesToLoad) => 28 | new PaginationParameters { MaximumPagesToLoad = maxPagesToLoad }; 29 | } 30 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/RequestDelay.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | 9 | namespace FacebookApiSharp.Classes 10 | { 11 | public class RequestDelay : IRequestDelay 12 | { 13 | private RequestDelay(int minSeconds, int maxSeconds) 14 | { 15 | _minSeconds = minSeconds; 16 | _maxSeconds = maxSeconds; 17 | _random = new Random(DateTime.Now.Millisecond); 18 | _isEnabled = true; 19 | } 20 | 21 | public static IRequestDelay FromSeconds(int min, int max) 22 | { 23 | if (min > max) 24 | { 25 | throw new ArgumentException("Value max should be bigger that value min"); 26 | } 27 | 28 | if (max < 0) 29 | { 30 | throw new ArgumentException("Both min and max values should be bigger than 0"); 31 | } 32 | 33 | return new RequestDelay(min, max); 34 | } 35 | 36 | public static IRequestDelay Empty() 37 | { 38 | return new RequestDelay(0, 0); 39 | } 40 | 41 | private readonly Random _random; 42 | private readonly int _minSeconds; 43 | private readonly int _maxSeconds; 44 | private bool _isEnabled; 45 | 46 | public TimeSpan Value => Exist ? TimeSpan.FromSeconds(_random.Next(_minSeconds, _maxSeconds)) : TimeSpan.Zero; 47 | 48 | public bool Exist => _isEnabled && _minSeconds != 0 && _maxSeconds != 0; 49 | 50 | public void Enable() 51 | { 52 | _isEnabled = true; 53 | } 54 | 55 | public void Disable() 56 | { 57 | _isEnabled = false; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/DefaultResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes 13 | { 14 | public class DefaultResponse 15 | { 16 | [JsonProperty("status")] public string Status { get; set; } 17 | 18 | public bool IsOk() 19 | { 20 | return !string.IsNullOrEmpty(Status) && Status.ToLower() == "ok"; 21 | } 22 | 23 | public bool IsFail() 24 | { 25 | return !string.IsNullOrEmpty(Status) && Status.ToLower() == "fail"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookActorResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookActorResponse 12 | { 13 | [JsonProperty("__typename")] 14 | public string Typename { get; set; } 15 | [JsonProperty("id")] 16 | public string Id { get; set; } 17 | [JsonProperty("friendship_status")] 18 | public string FriendshipStatus { get; set; } 19 | [JsonProperty("gender")] 20 | public string Gender { get; set; } 21 | [JsonProperty("name")] 22 | public string Name { get; set; } 23 | [JsonProperty("profile_picture")] 24 | public FacebookProfilePictureResponse ProfilePicture { get; set; } 25 | //public FacebookStoryBucketResponse story_bucket { get; set; } 26 | [JsonProperty("strong_id__")] 27 | public string StrongId { get; set; } 28 | [JsonProperty("is_work_user")] 29 | public bool IsWorkUser { get; set; } 30 | [JsonProperty("is_verified")] 31 | public bool IsVerified { get; set; } 32 | [JsonProperty("subscribe_status")] 33 | public string SubscribeStatus { get; set; } 34 | [JsonProperty("secondary_subscribe_status")] 35 | public string SecondarySubscribeStatus { get; set; } 36 | [JsonProperty("short_name")] 37 | public string ShortName { get; set; } 38 | [JsonProperty("is_favorite")] 39 | public bool IsFavorite { get; set; } 40 | [JsonProperty("url")] 41 | public string Url { get; set; } 42 | [JsonProperty("can_viewer_block")] 43 | public bool? CanViewerBlock { get; set; } 44 | [JsonProperty("profile_action")] 45 | public FacebookProfileActionResponse ProfileAction { get; set; } 46 | } 47 | 48 | public class FacebookProfilePictureResponse 49 | { 50 | [JsonProperty("uri")] 51 | public string Uri { get; set; } 52 | [JsonProperty("width")] 53 | public int Width { get; set; } 54 | [JsonProperty("height")] 55 | public int Height { get; set; } 56 | } 57 | 58 | public class FacebookProfileActionResponse 59 | { 60 | [JsonProperty("__typename")] 61 | public string Typename { get; set; } 62 | [JsonProperty("should_show_ap_disclaimer")] 63 | public bool ShouldShowApDisclaimer { get; set; } 64 | [JsonProperty("id")] 65 | public string Id { get; set; } 66 | [JsonProperty("strong_id__")] 67 | public string StrongId { get; set; } 68 | } 69 | 70 | //public class FacebookStoryBucketResponse 71 | //{ 72 | // public FacebookStoryBucketNodeResponse[] nodes { get; set; } 73 | //} 74 | 75 | //public class FacebookStoryBucketNodeResponse 76 | //{ 77 | // public string id { get; set; } 78 | // public bool is_bucket_seen_by_viewer { get; set; } 79 | // public bool is_bucket_owned_by_viewer { get; set; } 80 | // public string camera_post_type { get; set; } 81 | // public Threads threads { get; set; } 82 | // public int latest_thread_creation_time { get; set; } 83 | //} 84 | 85 | //public class Threads 86 | //{ 87 | // public bool is_empty { get; set; } 88 | //} 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookFailureLoginResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookFailureLoginResponse 12 | { 13 | [JsonProperty("error")] 14 | public FacebookFailureLoginErrorResponse Error { get; set; } 15 | } 16 | 17 | public class FacebookFailureLoginErrorResponse 18 | { 19 | [JsonProperty("message")] 20 | public string Message { get; set; } 21 | [JsonProperty("type")] 22 | public string Type { get; set; } 23 | [JsonProperty("code")] 24 | public int Code { get; set; } 25 | [JsonProperty("error_data")] 26 | public FacebookFailureLoginErrorDataResponse ErrorData { get; set; } 27 | [JsonProperty("error_subcode")] 28 | public int ErrorSubcode { get; set; } 29 | [JsonProperty("is_transient")] 30 | public bool IsTransient { get; set; } 31 | [JsonProperty("error_user_title")] 32 | public string ErrorUserTitle { get; set; } 33 | [JsonProperty("error_user_msg")] 34 | public string ErrorUserMsg { get; set; } 35 | [JsonProperty("fbtrace_id")] 36 | public string FbtraceId { get; set; } 37 | } 38 | 39 | public class FacebookFailureLoginErrorDataResponse 40 | { 41 | [JsonProperty("pwd_enc_key_pkg")] 42 | public FacebookPwdEncKeyPkgResponse PwdEncKeyPkg { get; set; } 43 | [JsonProperty("error_subcode")] 44 | public int ErrorSubcode { get; set; } 45 | [JsonProperty("cpl_info")] 46 | public FacebookFailureLoginErrorDataCplInfoResponse CplInfo { get; set; } 47 | 48 | } 49 | 50 | public class FacebookPwdEncKeyPkgResponse 51 | { 52 | [JsonProperty("key_id")] 53 | public int KeyId { get; set; } 54 | [JsonProperty("public_key")] 55 | public string PublicKey { get; set; } 56 | [JsonProperty("seconds_to_live")] 57 | public int SecondsToLive { get; set; } 58 | } 59 | public class FacebookFailureLoginErrorDataCplInfoResponse 60 | { 61 | [JsonProperty("id")] 62 | public string Id { get; set; } 63 | [JsonProperty("name")] 64 | public string Name { get; set; } 65 | [JsonProperty("profile_pic_uri")] 66 | public string ProfilePicUri { get; set; } 67 | [JsonProperty("cpl_eligible")] 68 | public bool CplEligible { get; set; } 69 | [JsonProperty("cpl_after_openid")] 70 | //public Contactpoints contactpoints { get; set; } 71 | public bool CplAfterOpenid { get; set; } 72 | [JsonProperty("cpl_group")] 73 | public int CplGroup { get; set; } 74 | [JsonProperty("first_name")] 75 | public string FirstName { get; set; } 76 | [JsonProperty("password_reset_nonce_length")] 77 | public int PasswordResetNonceLength { get; set; } 78 | [JsonProperty("cpl_sms_retriever_auto_submit_test_group")] 79 | public string CplSmsRetrieverAutoSubmitTestGroup { get; set; } 80 | [JsonProperty("nonce_send_status")] 81 | public int NonceSendStatus { get; set; } 82 | [JsonProperty("show_dbl_cpl_interstitial")] 83 | public bool ShowDblCplInterstitial { get; set; } 84 | } 85 | 86 | //public class Contactpoints 87 | //{ 88 | // public _0 _0 { get; set; } 89 | //} 90 | 91 | //public class _0 92 | //{ 93 | // public string id { get; set; } 94 | // public string display { get; set; } 95 | // public string type { get; set; } 96 | //} 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookLocaleLanguages.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System.Collections.Generic; 9 | 10 | namespace FacebookApiSharp.Classes.Responses 11 | { 12 | public class FacebookLocaleLanguages 13 | { 14 | [JsonProperty("locales")] 15 | public List Locales { get; set; } = new List(); 16 | } 17 | 18 | public class FacebookLocale 19 | { 20 | [JsonProperty("locale")] 21 | public string Locale { get; set; } 22 | [JsonProperty("weight")] 23 | public float Weight { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookLoggingEvents.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookLoggingClientEvents 12 | 13 | { 14 | [JsonProperty("checksum")] 15 | public string Checksum { get; set; } 16 | [JsonProperty("config")] 17 | public string Config { get; set; } 18 | [JsonProperty("config_owner_id")] 19 | public string ConfigOwnerId { get; set; } 20 | [JsonProperty("app_data")] 21 | public string AppData { get; set; } 22 | [JsonProperty("qpl_version")] 23 | public string QplVersion { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookLoginApprovalsKeyResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookLoginApprovalsKeyResponse 12 | { 13 | [JsonProperty("key")] 14 | public string Key { get; set; } 15 | [JsonProperty("time_offset")] 16 | public string TimeOffset { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookLoginSessionResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookLoginSessionResponse 12 | { 13 | [JsonProperty("session_key")] 14 | public string SessionKey { get; set; } 15 | [JsonProperty("uid")] 16 | public long UId { get; set; } 17 | [JsonProperty("secret")] 18 | public string Secret { get; set; } 19 | [JsonProperty("access_token")] 20 | public string AccessToken { get; set; } 21 | [JsonProperty("session_cookies")] 22 | public FacebookLoginSessionCookieResponse[] SessionCookies { get; set; } 23 | [JsonProperty("analytics_claim")] 24 | public string AnalyticsClaim { get; set; } 25 | [JsonProperty("confirmed")] 26 | public bool Confirmed { get; set; } 27 | [JsonProperty("identifier")] 28 | public string Identifier { get; set; } 29 | [JsonProperty("user_storage_key")] 30 | public string UserStorageKey { get; set; } 31 | } 32 | 33 | public class FacebookLoginSessionCookieResponse 34 | { 35 | [JsonProperty("name")] 36 | public string Name { get; set; } 37 | [JsonProperty("value")] 38 | public string Value { get; set; } 39 | [JsonProperty("expires")] 40 | public string Expires { get; set; } 41 | [JsonProperty("expires_timestamp")] 42 | public long ExpiresTimestamp { get; set; } 43 | [JsonProperty("domain")] 44 | public string Domain { get; set; } 45 | [JsonProperty("path")] 46 | public string Path { get; set; } 47 | [JsonProperty("secure")] 48 | public bool Secure { get; set; } 49 | [JsonProperty("httponly")] 50 | public bool HttpOnly { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookMessageResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookMessageContainerResponse 12 | { 13 | [JsonProperty("data")] 14 | public FacebookMessageDataResponse Data { get; set; } 15 | [JsonProperty("extensions")] 16 | public FacebookPageResultExtensionsResponse Extensions { get; set; } 17 | } 18 | public class FacebookMessageDataResponse 19 | { 20 | [JsonProperty("messaging_in_blue_send_message")] 21 | public FacebookMessagingInBlueSendMessageResponse MessagingInBlueSendMessage { get; set; } 22 | } 23 | 24 | public class FacebookMessagingInBlueSendMessageResponse 25 | { 26 | [JsonProperty("client_mutation_id")] 27 | public string ClientMutationId { get; set; } 28 | [JsonProperty("message")] 29 | public FacebookMessageResponse Message { get; set; } 30 | } 31 | 32 | public class FacebookMessageResponse 33 | { 34 | [JsonProperty("__typename")] 35 | public string Typename { get; set; } 36 | [JsonProperty("message_id")] 37 | public string MessageId { get; set; } 38 | [JsonProperty("offline_threading_id")] 39 | public string OfflineThreadingId { get; set; } 40 | [JsonProperty("timestamp_precise")] 41 | public string TimestampPrecise { get; set; } 42 | [JsonProperty("snippet")] 43 | public string Snippet { get; set; } 44 | [JsonProperty("unsent_timestamp_precise")] 45 | public string UnsentTimestampPrecise { get; set; } 46 | [JsonProperty("message_sender")] 47 | public FacebookMessageSenderResponse MessageSender { get; set; } 48 | [JsonProperty("message")] 49 | public FacebookInnerMessageResponse Message { get; set; } 50 | [JsonProperty("id")] 51 | public string Id { get; set; } 52 | [JsonProperty("tags_list")] 53 | public string[] TagsList { get; set; } 54 | [JsonProperty("strong_id__")] 55 | public string StrongId { get; set; } 56 | } 57 | 58 | public class FacebookMessageSenderResponse 59 | { 60 | [JsonProperty("id")] 61 | public string Id { get; set; } 62 | [JsonProperty("messaging_actor")] 63 | public FacebookActorResponse MessagingActor { get; set; } 64 | } 65 | 66 | 67 | public class FacebookInnerMessageResponse 68 | { 69 | [JsonProperty("text")] 70 | public string Text { get; set; } 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookMobileGateKeepers.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | namespace FacebookApiSharp.Classes.Responses 9 | { 10 | public class FacebookMobileGateKeepers 11 | { 12 | [JsonProperty("result")] 13 | public string Result { get; set; } 14 | [JsonProperty("hash")] 15 | public string Hash { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookNetworkInterfaceResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes 10 | { 11 | public class FacebookNetworkInterfaceResponse 12 | { 13 | [JsonProperty("version")] 14 | public int Version { get; set; } 15 | [JsonProperty("cat_param")] 16 | public string CatParam { get; set; } 17 | [JsonProperty("rules")] 18 | public object Rules { get; set; } 19 | [JsonProperty("hints")] 20 | public object Hints { get; set; } 21 | [JsonProperty("token")] 22 | public string Token { get; set; } 23 | [JsonProperty("timestamp")] 24 | public long Timestamp { get; set; } 25 | [JsonProperty("tgt_ip")] 26 | public string TgtIp { get; set; } 27 | [JsonProperty("net_iface")] 28 | public string NetIface { get; set; } 29 | [JsonProperty("reason")] 30 | public string Reason { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookPageResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System.Collections.Generic; 9 | 10 | namespace FacebookApiSharp.Classes.Responses 11 | { 12 | public class FacebookPaginationResultResponse where T : class 13 | { 14 | [JsonProperty("label")] 15 | public string Label { get; set; } 16 | [JsonProperty("path")] 17 | public string[] Path { get; set; } 18 | [JsonProperty("data")] 19 | public T Data { get; set; } 20 | [JsonProperty("extensions")] 21 | public FacebookPageResultExtensionsResponse Extensions { get; set; } 22 | [JsonProperty("errors")] 23 | public List Errors = new List(); 24 | } 25 | public class FacebookPaginationResultResponse 26 | { 27 | [JsonProperty("label")] 28 | public string Label { get; set; } 29 | [JsonProperty("path")] 30 | public string[] Path { get; set; } 31 | [JsonProperty("data")] 32 | public FacebookPageResultDataResponse Data { get; set; } 33 | [JsonProperty("extensions")] 34 | public FacebookPageResultExtensionsResponse Extensions { get; set; } 35 | } 36 | 37 | public class FacebookPageResultDataResponse 38 | { 39 | [JsonProperty("page_info")] 40 | public FacebookPageInfoResponse PageInfo { get; set; } 41 | } 42 | 43 | public class FacebookPageInfoResponse 44 | { 45 | [JsonProperty("start_cursor")] 46 | public string StartCursor { get; set; } 47 | [JsonProperty("end_cursor")] 48 | public string EndCursor { get; set; } 49 | [JsonProperty("has_previous_page")] 50 | public bool HasPreviousPage { get; set; } 51 | [JsonProperty("has_next_page")] 52 | public bool HasNextPage { get; set; } 53 | } 54 | 55 | public class FacebookPageResultExtensionsResponse 56 | { 57 | [JsonProperty("is_final")] 58 | public bool IsFinal { get; set; } 59 | [JsonProperty("fulfilled_payloads")] 60 | public FacebookPageResultExtensionsFulfilledPayloadsResponse[] FulfilledPayloads { get; set; } 61 | [JsonProperty("server_metadata")] 62 | public FacebookPageResultExtensionsServerMetadataResponse ServerMetadata { get; set; } 63 | } 64 | 65 | public class FacebookPageResultExtensionsServerMetadataResponse 66 | { 67 | [JsonProperty("request_start_time_ms")] 68 | public long RequestStartTimeMs { get; set; } 69 | [JsonProperty("time_at_flush_ms")] 70 | public long TimeAtFlushMs { get; set; } 71 | } 72 | 73 | public class FacebookPageResultExtensionsFulfilledPayloadsResponse 74 | { 75 | [JsonProperty("label")] 76 | public string Label { get; set; } 77 | [JsonProperty("path")] 78 | public object[] Path { get; set; } 79 | } 80 | 81 | public class FacebookErrorResultContainer 82 | { 83 | [JsonProperty("error")] 84 | public FacebookErrorResult Error { get; set; } 85 | } 86 | public class FacebookErrorResult 87 | { 88 | [JsonProperty("message")] 89 | public string Message { get; set; } 90 | 91 | [JsonProperty("severity")] 92 | public string Severity { get; set; } 93 | 94 | [JsonProperty("code")] 95 | public int? Code { get; set; } 96 | 97 | [JsonProperty("api_error_code")] 98 | public int? ApiErrorCode { get; set; } 99 | 100 | [JsonProperty("summary")] 101 | public string Summary { get; set; } 102 | 103 | [JsonProperty("description")] 104 | public string Description { get; set; } 105 | 106 | //[JsonProperty("description_raw")] 107 | //public DescriptionRaw DescriptionRaw { get; set; } 108 | 109 | [JsonProperty("is_silent")] 110 | public bool? IsSilent { get; set; } 111 | 112 | [JsonProperty("is_transient")] 113 | public bool? IsTransient { get; set; } 114 | 115 | [JsonProperty("requires_reauth")] 116 | public bool? RequiresReauth { get; set; } 117 | 118 | [JsonProperty("allow_user_retry")] 119 | public bool? AllowUserRetry { get; set; } 120 | 121 | [JsonProperty("debug_info")] 122 | public object DebugInfo { get; set; } 123 | 124 | [JsonProperty("query_path")] 125 | public object QueryPath { get; set; } 126 | 127 | [JsonProperty("fbtrace_id")] 128 | public string FbtraceId { get; set; } 129 | 130 | [JsonProperty("www_request_id")] 131 | public string WwwRequestId { get; set; } 132 | 133 | [JsonProperty("sentry_block_user_info")] 134 | public FacebookErrortSentryBlockUserInfo SentryBlockUserInfo { get; set; } 135 | 136 | [JsonProperty("path")] 137 | public List Path { get; set; } = new List(); 138 | [JsonProperty("type")] 139 | public string Type { get; set; } 140 | } 141 | public class FacebookErrortSentryBlockUserInfo 142 | { 143 | [JsonProperty("sentry_block_data")] 144 | public string SentryBlockData { get; set; } 145 | } 146 | //public class DescriptionRaw 147 | //{ 148 | // [JsonProperty("__html")] 149 | // public string Html { get; set; } 150 | //} 151 | 152 | 153 | } 154 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/FacebookZeroHeadersPingParams.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookZeroHeadersPingParams 12 | { 13 | [JsonProperty("clear")] 14 | public bool Clear { get; set; } 15 | [JsonProperty("next_cursor")] 16 | public string NextCursor { get; set; } 17 | [JsonProperty("cooldown_on_success")] 18 | public int CooldownOnSuccess { get; set; } 19 | [JsonProperty("cooldown_on_failure")] 20 | public int CooldownOnFailure { get; set; } 21 | [JsonProperty("transparency_content_type")] 22 | public int TransparencyContentType { get; set; } 23 | [JsonProperty("carrier_id")] 24 | public int CarrierId { get; set; } 25 | [JsonProperty("consent_required")] 26 | public bool ConsentRequired { get; set; } 27 | [JsonProperty("client_header_params")] 28 | public FacebookClientHeaderParams ClientHeaderParams { get; set; } 29 | [JsonProperty("headwind_immediate")] 30 | public bool HeadwindImmediate { get; set; } 31 | [JsonProperty("user_signal_required")] 32 | public bool UserSignalRequired { get; set; } 33 | } 34 | 35 | public class FacebookClientHeaderParams 36 | { 37 | [JsonProperty("is_jio_headers_enabled")] 38 | public bool IsJioHeadersEnabled { get; set; } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Media/FacebookLinkPreviewResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookLinkPreviewDataResponse 12 | { 13 | [JsonProperty("link_preview")] 14 | public FacebookLinkPreviewResponse LinkPreview { get; set; } 15 | } 16 | 17 | public class FacebookLinkPreviewResponse 18 | { 19 | [JsonProperty("share_scrape_data")] 20 | public string ShareScrapeData { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Media/FacebookStoryResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes.Responses 13 | { 14 | public class FacebookEntityResponse 15 | { 16 | [JsonProperty("__typename")] 17 | public string Typename { get; set; } 18 | 19 | [JsonProperty("id")] 20 | public string Id { get; set; } 21 | 22 | [JsonProperty("strong_id__")] 23 | public string StrongId { get; set; } 24 | 25 | [JsonProperty("name")] 26 | public string Name { get; set; } 27 | 28 | [JsonProperty("url")] 29 | public string Url { get; set; } 30 | } 31 | 32 | public class Ranx 33 | { 34 | [JsonProperty("offset")] 35 | public int Offset { get; set; } 36 | 37 | [JsonProperty("length")] 38 | public int Length { get; set; } 39 | 40 | [JsonProperty("entity")] 41 | public FacebookEntityResponse Entity { get; set; } 42 | } 43 | 44 | public class Message 45 | { 46 | [JsonProperty("text")] 47 | public string Text { get; set; } 48 | 49 | [JsonProperty("ranges")] 50 | public List Ranges { get; set; } 51 | } 52 | 53 | public class FacebookImage 54 | { 55 | [JsonProperty("uri")] 56 | public string Uri { get; set; } 57 | 58 | [JsonProperty("width")] 59 | public int Width { get; set; } 60 | 61 | [JsonProperty("height")] 62 | public int Height { get; set; } 63 | } 64 | 65 | public class FacebookCreationStory 66 | { 67 | [JsonProperty("id")] 68 | public string Id { get; set; } 69 | 70 | [JsonProperty("cache_id")] 71 | public string CacheId { get; set; } 72 | } 73 | 74 | public class FacebookOwner 75 | { 76 | [JsonProperty("__typename")] 77 | public string Typename { get; set; } 78 | 79 | [JsonProperty("id")] 80 | public string Id { get; set; } 81 | 82 | [JsonProperty("name")] 83 | public string Name { get; set; } 84 | 85 | [JsonProperty("strong_id__")] 86 | public string StrongId { get; set; } 87 | } 88 | 89 | public class FacebookTarget 90 | { 91 | [JsonProperty("__typename")] 92 | public string Typename { get; set; } 93 | 94 | [JsonProperty("id")] 95 | public string Id { get; set; } 96 | 97 | [JsonProperty("strong_id__")] 98 | public string StrongId { get; set; } 99 | 100 | [JsonProperty("image")] 101 | public FacebookImage Image { get; set; } 102 | 103 | [JsonProperty("creation_story")] 104 | public FacebookCreationStory CreationStory { get; set; } 105 | 106 | [JsonProperty("owner")] 107 | public FacebookOwner Owner { get; set; } 108 | } 109 | 110 | public class Media 111 | { 112 | [JsonProperty("__typename")] 113 | public string Typename { get; set; } 114 | 115 | [JsonProperty("id")] 116 | public string Id { get; set; } 117 | 118 | [JsonProperty("strong_id__")] 119 | public string StrongId { get; set; } 120 | 121 | [JsonProperty("image")] 122 | public FacebookImage Image { get; set; } 123 | 124 | [JsonProperty("imageLow")] 125 | public FacebookImage ImageLow { get; set; } 126 | 127 | [JsonProperty("imageMedium")] 128 | public FacebookImage ImageMedium { get; set; } 129 | 130 | [JsonProperty("imageHigh")] 131 | public FacebookImage ImageHigh { get; set; } 132 | 133 | [JsonProperty("owner")] 134 | public FacebookOwner Owner { get; set; } 135 | } 136 | 137 | public class FacebookAttachment 138 | { 139 | [JsonProperty("title")] 140 | public string Title { get; set; } 141 | 142 | [JsonProperty("url")] 143 | public string Url { get; set; } 144 | 145 | [JsonProperty("media_reference_token")] 146 | public string MediaReferenceToken { get; set; } 147 | 148 | [JsonProperty("target")] 149 | public FacebookTarget Target { get; set; } 150 | 151 | [JsonProperty("deduplication_key")] 152 | public string DeduplicationKey { get; set; } 153 | 154 | [JsonProperty("use_carousel_infinite_scroll")] 155 | public bool UseCarouselInfiniteScroll { get; set; } 156 | 157 | [JsonProperty("is_mute_music_ad")] 158 | public bool IsMuteMusicAd { get; set; } 159 | 160 | [JsonProperty("media")] 161 | public Media Media { get; set; } 162 | } 163 | 164 | public class FacebookFeedbackStory 165 | { 166 | [JsonProperty("id")] 167 | public string Id { get; set; } 168 | public override string ToString() 169 | { 170 | return Id; 171 | } 172 | } 173 | 174 | public class FacebookStory 175 | { 176 | [JsonProperty("__typename")] 177 | public string Typename { get; set; } 178 | 179 | [JsonProperty("strong_id__")] 180 | public string StrongId { get; set; } 181 | 182 | [JsonProperty("id")] 183 | public string Id { get; set; } 184 | 185 | [JsonProperty("cache_id")] 186 | public string CacheId { get; set; } 187 | 188 | [JsonProperty("creation_time")] 189 | public int CreationTime { get; set; } 190 | [JsonProperty("feedback")] 191 | public FacebookFeedbackStory Feedback { get; set; } 192 | 193 | [JsonProperty("url")] 194 | public string Url { get; set; } 195 | 196 | [JsonProperty("message")] 197 | public Message Message { get; set; } 198 | 199 | [JsonProperty("is_fox_sharable")] 200 | public bool IsFoxSharable { get; set; } 201 | 202 | [JsonProperty("post_id")] 203 | public string PostId { get; set; } 204 | 205 | [JsonProperty("actors")] 206 | public List Actors { get; set; } = new List(); 207 | 208 | [JsonProperty("tracking")] 209 | public string Tracking { get; set; } 210 | 211 | [JsonProperty("privacy_label")] 212 | public string PrivacyLabel { get; set; } 213 | 214 | [JsonProperty("legacy_api_story_id")] 215 | public string LegacyApiStoryId { get; set; } 216 | 217 | [JsonProperty("hideable_token")] 218 | public string HideableToken { get; set; } 219 | 220 | [JsonProperty("can_viewer_append_photos")] 221 | public bool CanViewerAppendPhotos { get; set; } 222 | 223 | [JsonProperty("can_viewer_edit")] 224 | public bool CanViewerEdit { get; set; } 225 | 226 | [JsonProperty("can_viewer_edit_metatags")] 227 | public bool CanViewerEditMetatags { get; set; } 228 | 229 | [JsonProperty("can_viewer_edit_post_media")] 230 | public bool CanViewerEditPostMedia { get; set; } 231 | 232 | [JsonProperty("can_viewer_edit_post_privacy")] 233 | public bool CanViewerEditPostPrivacy { get; set; } 234 | 235 | [JsonProperty("can_viewer_edit_link_attachment")] 236 | public bool CanViewerEditLinkAttachment { get; set; } 237 | 238 | [JsonProperty("can_viewer_delete")] 239 | public bool CanViewerDelete { get; set; } 240 | 241 | [JsonProperty("can_viewer_end_qna")] 242 | public bool CanViewerEndQna { get; set; } 243 | 244 | [JsonProperty("can_viewer_see_community_popular_waist")] 245 | public bool CanViewerSeeCommunityPopularWaist { get; set; } 246 | 247 | [JsonProperty("can_viewer_reshare_to_story")] 248 | public bool CanViewerReshareToStory { get; set; } 249 | 250 | [JsonProperty("can_viewer_reshare_to_story_now")] 251 | public bool CanViewerReshareToStoryNow { get; set; } 252 | 253 | [JsonProperty("substory_count")] 254 | public int SubstoryCount { get; set; } 255 | 256 | [JsonProperty("is_automatically_translated")] 257 | public bool IsAutomaticallyTranslated { get; set; } 258 | 259 | [JsonProperty("is_eligible_for_affiliate_commission")] 260 | public bool IsEligibleForAffiliateCommission { get; set; } 261 | 262 | [JsonProperty("has_comprehensive_title")] 263 | public bool HasComprehensiveTitle { get; set; } 264 | 265 | [JsonProperty("viewer_edit_post_feature_capabilities")] 266 | public List ViewerEditPostFeatureCapabilities { get; set; } 267 | 268 | [JsonProperty("is_anonymous")] 269 | public bool IsAnonymous { get; set; } 270 | 271 | [JsonProperty("can_viewer_approve_post")] 272 | public bool CanViewerApprovePost { get; set; } 273 | 274 | [JsonProperty("should_show_easy_hide")] 275 | public bool ShouldShowEasyHide { get; set; } 276 | 277 | [JsonProperty("attachments")] 278 | public List Attachments { get; set; } 279 | 280 | [JsonProperty("is_marked_as_spam_by_admin_assistant")] 281 | public bool IsMarkedAsSpamByAdminAssistant { get; set; } 282 | } 283 | 284 | public class FacebookStoryCreate 285 | { 286 | [JsonProperty("story")] 287 | public FacebookStory Story { get; set; } 288 | 289 | [JsonProperty("logging_token")] 290 | public string LoggingToken { get; set; } 291 | } 292 | 293 | public class FacebookStoryCreateData 294 | { 295 | [JsonProperty("story_create")] 296 | public FacebookStoryCreate StoryCreate { get; set; } 297 | } 298 | 299 | 300 | } 301 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Messaging/FacebookInboxFriendsResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | 9 | namespace FacebookApiSharp.Classes.Responses 10 | { 11 | public class FacebookInboxFriendsResponse 12 | { 13 | [JsonProperty("data")] 14 | public FacebookInboxFriendsDataResponse Data { get; set; } 15 | [JsonProperty("extensions")] 16 | public FacebookPageResultExtensionsResponse Extensions { get; set; } 17 | } 18 | 19 | public class FacebookInboxFriendsDataResponse 20 | { 21 | [JsonProperty("viewer")] 22 | public FacebookInboxFriendsViewerResponse Viewer { get; set; } 23 | } 24 | 25 | public class FacebookInboxFriendsViewerResponse 26 | { 27 | [JsonProperty("account_user")] 28 | public FacebookInboxFriendsUserAccountResponse AccountUser { get; set; } 29 | } 30 | 31 | public class FacebookInboxFriendsUserAccountResponse 32 | { 33 | [JsonProperty("friends")] 34 | public FacebookInboxFriendsUserResponse Friends { get; set; } 35 | [JsonProperty("id")] 36 | public string Id { get; set; } 37 | [JsonProperty("top_friends")] 38 | public FacebookInboxFriendsUserResponse TopFriends { get; set; } 39 | [JsonProperty("top_friends_with_messenger")] 40 | public FacebookInboxFriendsUserResponse TopFriendsWithMessenger { get; set; } 41 | } 42 | 43 | public class FacebookInboxFriendsUserResponse 44 | { 45 | [JsonProperty("count")] 46 | public int Count { get; set; } 47 | [JsonProperty("nodes")] 48 | public FacebookInboxFriendsUserNodeResponse[] Nodes { get; set; } 49 | } 50 | 51 | public class FacebookInboxFriendsUserNodeResponse 52 | { 53 | [JsonProperty("name")] 54 | public string Name { get; set; } 55 | [JsonProperty("short_name")] 56 | public string ShortName { get; set; } 57 | [JsonProperty("profile_picture")] 58 | public FacebookProfilePictureResponse ProfilePicture { get; set; } 59 | [JsonProperty("id")] 60 | public string Id { get; set; } 61 | [JsonProperty("last_active_messages_status")] 62 | public FacebookInboxFriendsUserNodeLastActivityResponse LastActiveMessagesStatus { get; set; } 63 | } 64 | public class FacebookInboxFriendsUserNodeLastActivityResponse 65 | { 66 | [JsonProperty("is_currently_active")] 67 | public string IsCurrentlyActive { get; set; } 68 | [JsonProperty("time")] 69 | public long? Time { get; set; } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Users/FacebookLoginActivityResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using FacebookApiSharp.Helpers; 11 | 12 | namespace FacebookApiSharp.Classes.Responses 13 | { 14 | public class FacebookSummary 15 | { 16 | [JsonProperty("text")] 17 | public string Text { get; set; } 18 | } 19 | 20 | public class FacebookLoginActivityNodeResponse 21 | { 22 | [JsonProperty("id")] 23 | public string Id { get; set; } 24 | 25 | [JsonProperty("creation_time")] 26 | public long CreationTimeAtUnix { get; set; } 27 | public DateTime CreationTime => CreationTimeAtUnix.FromUnixTimeSeconds(); 28 | 29 | [JsonProperty("summary")] 30 | public FacebookSummary Summary { get; set; } 31 | 32 | [JsonProperty("message")] 33 | public FacebookSummary Message { get; set; } 34 | 35 | [JsonProperty("__typename")] 36 | public string Typename { get; set; } 37 | } 38 | 39 | public class FacebookLoginActivityEdgeResponse 40 | { 41 | [JsonProperty("ent_fbid")] 42 | public string EntFbid { get; set; } 43 | 44 | [JsonProperty("node")] 45 | public FacebookLoginActivityNodeResponse Node { get; set; } 46 | 47 | [JsonProperty("do_not_link_actor")] 48 | public bool DoNotLinkActor { get; set; } 49 | 50 | [JsonProperty("cursor")] 51 | public string Cursor { get; set; } 52 | } 53 | 54 | public class FacebookLoginActivityStoriesResponse 55 | { 56 | [JsonProperty("edges")] 57 | public List Edges { get; set; } = new List(); 58 | 59 | [JsonProperty("page_info")] 60 | public FacebookPageInfoResponse PageInfo { get; set; } 61 | } 62 | 63 | public class FacebookActivityLogActorResponse 64 | { 65 | [JsonProperty("__typename")] 66 | public string Typename { get; set; } 67 | 68 | [JsonProperty("__isActivityLogActor")] 69 | public string IsActivityLogActor { get; set; } 70 | 71 | [JsonProperty("stories")] 72 | public FacebookLoginActivityStoriesResponse Stories { get; set; } 73 | 74 | [JsonProperty("__isNode")] 75 | public string IsNode { get; set; } 76 | 77 | [JsonProperty("id")] 78 | public string Id { get; set; } 79 | } 80 | 81 | public class FacebookLoginActivityDataViewerResponse 82 | { 83 | [JsonProperty("activity_log_actor")] 84 | public FacebookActivityLogActorResponse ActivityLogActor { get; set; } 85 | } 86 | 87 | public class FacebookLoginActivityDataResponse 88 | { 89 | [JsonProperty("viewer")] 90 | public FacebookLoginActivityDataViewerResponse Viewer { get; set; } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Users/FacebookLogout.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes.Responses 13 | { 14 | public class FacebookLogoutDataStory 15 | { 16 | [JsonProperty("id")] 17 | public string Id { get; set; } 18 | } 19 | 20 | public class FacebookLogoutDataStoryCuration 21 | { 22 | [JsonProperty("story")] 23 | public FacebookLogoutDataStory Story { get; set; } 24 | } 25 | 26 | public class FacebookLogoutData 27 | { 28 | [JsonProperty("activity_log_story_curation")] 29 | public FacebookLogoutDataStoryCuration ActivityLogStoryCuration { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Users/FacebookSearchData.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using FacebookApiSharp.Helpers; 11 | 12 | 13 | namespace FacebookApiSharp.Classes.Responses 14 | { 15 | public class FacebookSearchData 16 | { 17 | [JsonProperty("search_query")] 18 | public FacebookSearchDataQuery SearchQuery { get; set; } 19 | } 20 | 21 | public class FacebookSearchDataQueryNtBundleAttribute 22 | { 23 | [JsonProperty("__typename")] 24 | public string Typename { get; set; } 25 | 26 | [JsonProperty("name")] 27 | public string Name { get; set; } 28 | 29 | [JsonProperty("strong_id__")] 30 | public object StrongId { get; set; } 31 | 32 | [JsonProperty("recent_search_entity_value")] 33 | public FacebookActorResponse RecentSearchEntityValue { get; set; } 34 | } 35 | 36 | public class FacebookSearchDataQueryNativeTemplateBundle 37 | { 38 | [JsonProperty("nt_bundle_tree")] 39 | public string NtBundleTree { get; set; } 40 | 41 | [JsonProperty("nt_bundle_attributes")] 42 | public List NtBundleAttributes { get; set; } 43 | } 44 | 45 | public class FacebookSearchDataQueryNativeTemplateView 46 | { 47 | [JsonProperty("logging_id")] 48 | public string LoggingId { get; set; } 49 | 50 | [JsonProperty("data_diff_item_id")] 51 | public string DataDiffItemId { get; set; } 52 | 53 | [JsonProperty("data_diff_content_id")] 54 | public string DataDiffContentId { get; set; } 55 | 56 | [JsonProperty("unique_id")] 57 | public string UniqueId { get; set; } 58 | 59 | [JsonProperty("native_template_bundles")] 60 | public List NativeTemplateBundles { get; set; } 61 | } 62 | 63 | public class FacebookSearchDataQueryEdge 64 | { 65 | [JsonProperty("logging_unit_id")] 66 | public string LoggingUnitId { get; set; } 67 | 68 | [JsonProperty("module_role")] 69 | public string ModuleRole { get; set; } 70 | 71 | [JsonProperty("result_role")] 72 | public string ResultRole { get; set; } 73 | 74 | [JsonProperty("native_template_view")] 75 | public FacebookSearchDataQueryNativeTemplateView NativeTemplateView { get; set; } 76 | 77 | [JsonProperty("native_template_result_ids")] 78 | public List NativeTemplateResultIds { get; set; } 79 | } 80 | 81 | public class FacebookSearchDataQueryCombinedResults 82 | { 83 | [JsonProperty("has_hcm")] 84 | public bool HasHcm { get; set; } 85 | 86 | [JsonProperty("has_iem_triggered")] 87 | public bool HasIemTriggered { get; set; } 88 | 89 | [JsonProperty("edges")] 90 | public List Edges { get; set; } 91 | } 92 | 93 | public class FacebookSearchDataQuery 94 | { 95 | [JsonProperty("query_function")] 96 | public string QueryFunction { get; set; } 97 | 98 | [JsonProperty("logging_unit_id")] 99 | public string LoggingUnitId { get; set; } 100 | 101 | [JsonProperty("combined_results")] 102 | public FacebookSearchDataQueryCombinedResults CombinedResults { get; set; } 103 | 104 | [JsonProperty("cache_id")] 105 | public string CacheId { get; set; } 106 | } 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Responses/Users/Friends.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Classes.Responses 13 | { 14 | public class FacebookFriendsDataResponse 15 | { 16 | [JsonProperty("viewer")] 17 | public FacebookFriendsViewerResponse Viewer { get; set; } 18 | } 19 | 20 | public class FacebookFriendsViewerResponse 21 | { 22 | [JsonProperty("dynamic_friending_tab")] 23 | public FacebookFriendsDynamicFriendingResponse DynamicFriendingTab { get; set; } 24 | [JsonProperty("account_user")] 25 | public FacebookInboxFriendsUserAccountResponse AccountUser { get; set; } 26 | [JsonProperty("can_import_contacts")] 27 | public bool CanImportContacts { get; set; } 28 | } 29 | 30 | public class FacebookFriendsDynamicFriendingResponse 31 | { 32 | [JsonProperty("friend_request_count")] 33 | public int FriendRequestCount { get; set; } 34 | [JsonProperty("edges")] 35 | public FacebookFriendsDynamicEdgeResponse[] Edges { get; set; } 36 | [JsonProperty("page_info")] 37 | public FacebookPageInfoResponse PageInfo { get; set; } 38 | } 39 | 40 | public class FacebookFriendsDynamicEdgeResponse 41 | { 42 | [JsonProperty("node")] 43 | public FacebookFriendsDynamicEdgeNodeResponse Node { get; set; } 44 | } 45 | 46 | public class FacebookFriendsDynamicEdgeNodeResponse 47 | { 48 | [JsonProperty("__typename")] 49 | public string Typename { get; set; } 50 | [JsonProperty("show_see_all")] 51 | public bool ShowSeeAll { get; set; } 52 | [JsonProperty("type")] 53 | public string Type { get; set; } 54 | [JsonProperty("timestamp")] 55 | public long Timestamp { get; set; } 56 | [JsonProperty("user")] 57 | public FacebookActorResponse User { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/Result.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Responses; 8 | using FacebookApiSharp.Helpers; 9 | using Newtonsoft.Json; 10 | using System; 11 | using System.Net.Http; 12 | namespace FacebookApiSharp.Classes 13 | { 14 | public class Result : IResult 15 | { 16 | public Result(bool succeeded, T value, ResultInfo info) 17 | { 18 | Succeeded = succeeded; 19 | Value = value; 20 | Info = info; 21 | } 22 | 23 | public Result(bool succeeded, ResultInfo info) 24 | { 25 | Succeeded = succeeded; 26 | Info = info; 27 | } 28 | 29 | public Result(bool succeeded, T value) 30 | { 31 | Succeeded = succeeded; 32 | Value = value; 33 | } 34 | 35 | public bool Succeeded { get; } 36 | public T Value { get; } 37 | public ResultInfo Info { get; } = new ResultInfo(""); 38 | } 39 | 40 | public static class Result 41 | { 42 | public static IResult Success(T resValue) 43 | { 44 | return new Result(true, resValue, new ResultInfo(ResponseType.OK, "oK")); 45 | } 46 | 47 | public static IResult Success(string successMsg, T resValue) 48 | { 49 | return new Result(true, resValue, new ResultInfo(ResponseType.OK, successMsg)); 50 | } 51 | 52 | public static IResult Fail(Exception exception) 53 | { 54 | return new Result(false, default, new ResultInfo(exception)); 55 | } 56 | 57 | public static IResult Fail(string errMsg) 58 | { 59 | return new Result(false, default, new ResultInfo(errMsg)); 60 | } 61 | 62 | public static IResult Fail(string errMsg, T resValue) 63 | { 64 | return new Result(false, resValue, new ResultInfo(errMsg)); 65 | } 66 | 67 | public static IResult Fail(Exception exception, T resValue) 68 | { 69 | return new Result(false, resValue, new ResultInfo(exception)); 70 | } 71 | 72 | public static IResult Fail(Exception exception, T resValue, ResponseType responseType) 73 | { 74 | return new Result(false, resValue, new ResultInfo(exception, responseType)); 75 | } 76 | 77 | public static IResult Fail(ResultInfo info, T resValue) 78 | { 79 | return new Result(false, resValue, info); 80 | } 81 | 82 | public static IResult Fail(string errMsg, ResponseType responseType, T resValue) 83 | { 84 | return new Result(false, resValue, new ResultInfo(responseType, errMsg)); 85 | } 86 | 87 | public static IResult Fail(Exception exception, string json) 88 | { 89 | if (string.IsNullOrEmpty(json)) 90 | { 91 | var resultInfo = new ResultInfo(exception, ResponseType.UnExpectedResponse); 92 | return new Result(false, default, resultInfo); 93 | } 94 | else 95 | { 96 | return new Result(false, default, GenerateResult(json, null, exception)); 97 | } 98 | } 99 | public static IResult UnExpectedResponse(HttpResponseMessage response, string json) 100 | { 101 | if (string.IsNullOrEmpty(json)) 102 | { 103 | var resultInfo = new ResultInfo(ResponseType.UnExpectedResponse, 104 | $"Unexpected response status: {response.StatusCode}"); 105 | return new Result(false, default, resultInfo); 106 | } 107 | else 108 | { 109 | return new Result(false, default, GenerateResult(json)); 110 | } 111 | } 112 | 113 | public static IResult UnExpectedResponse(HttpResponseMessage response, 114 | string message, 115 | string json) 116 | { 117 | if (string.IsNullOrEmpty(json)) 118 | { 119 | var resultInfo = new ResultInfo(ResponseType.UnExpectedResponse, 120 | $"{message}\r\nUnexpected response status: {response.StatusCode}"); 121 | return new Result(false, default, resultInfo); 122 | } 123 | else 124 | { 125 | return new Result(false, default, GenerateResult(json, message)); 126 | } 127 | } 128 | private static ResultInfo GenerateResult(string json, string userMessage = null, Exception exception = null) 129 | { 130 | if (json.Contains("\"error\"")) 131 | { 132 | var obj = JsonConvert.DeserializeObject(json); 133 | string msg; 134 | if (!string.IsNullOrEmpty(userMessage)) 135 | msg = userMessage + Environment.NewLine + obj.Error?.Message; 136 | else 137 | msg = obj.Error?.Message; 138 | 139 | var resultInfo = new ResultInfo(ResponseType.UnExpectedResponse, msg) 140 | { 141 | Exception = exception 142 | }; 143 | if(obj.Error?.Type == "OAuthException") 144 | { 145 | resultInfo.ResponseType = ResponseType.OAuthException; 146 | } 147 | resultInfo.Errors.Add(obj.Error); 148 | return resultInfo; 149 | } 150 | else 151 | { 152 | var obj = JsonConvert.DeserializeObject>(json); 153 | string msg = string.Empty; 154 | if (!string.IsNullOrEmpty(userMessage)) 155 | msg = userMessage + Environment.NewLine; 156 | 157 | if (obj.Errors?.Count > 0) 158 | { 159 | foreach (var error in obj.Errors) 160 | { 161 | if (!string.IsNullOrEmpty(error.Summary)) 162 | { 163 | msg += $"{error.Message}{Environment.NewLine}//{Environment.NewLine}"; 164 | } 165 | else 166 | { 167 | msg += $"{error.Summary}{Environment.NewLine}{error.Description}{Environment.NewLine}//{Environment.NewLine}"; 168 | } 169 | } 170 | } 171 | 172 | return new ResultInfo(ResponseType.UnExpectedResponse, msg) 173 | { 174 | Errors = obj.Errors, 175 | Exception = exception 176 | }; 177 | } 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/ResultInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Responses; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text.RegularExpressions; 11 | 12 | namespace FacebookApiSharp.Classes 13 | { 14 | public class ResultInfo 15 | { 16 | public ResultInfo(string message) 17 | { 18 | Message = message; 19 | HandleMessages(message); 20 | } 21 | 22 | public ResultInfo(Exception exception) 23 | { 24 | Exception = exception; 25 | Message = exception?.Message; 26 | ResponseType = ResponseType.InternalException; 27 | HandleMessages(Message); 28 | } 29 | 30 | public ResultInfo(Exception exception, ResponseType responseType) 31 | { 32 | Exception = exception; 33 | Message = exception?.Message; 34 | ResponseType = responseType; 35 | HandleMessages(Message); 36 | } 37 | 38 | public ResultInfo(ResponseType responseType, string errorMessage) 39 | { 40 | ResponseType = responseType; 41 | Message = errorMessage; 42 | HandleMessages(errorMessage); 43 | } 44 | public ResultInfo(ResponseType responseType, DefaultResponse status) 45 | { 46 | ResponseType = responseType; 47 | HandleMessages(Message); 48 | } 49 | public void HandleMessages(string errorMessage) 50 | { 51 | if (errorMessage?.Contains("task was canceled") ?? false) 52 | Timeout = true; 53 | } 54 | 55 | public Exception Exception { get; internal set; } 56 | 57 | public string Message { get; } 58 | 59 | public ResponseType ResponseType { get; internal set; } 60 | 61 | public bool Timeout { get; internal set; } 62 | 63 | 64 | public List Errors { get; internal set; } = new List(); 65 | 66 | public override string ToString() 67 | { 68 | return $"{ResponseType}: {Message}."; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/SessionHandlers/FileSessionHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using System.IO; 9 | 10 | namespace FacebookApiSharp.Classes.SessionHandlers 11 | { 12 | public class FileSessionHandler : ISessionHandler 13 | { 14 | public IFacebookApi FacebookApi { get; set; } 15 | /// 16 | /// Path to file 17 | /// 18 | public string FilePath { get; set; } 19 | 20 | /// 21 | /// Load and Set StateData to InstaApi 22 | /// 23 | public void Load() 24 | { 25 | if (File.Exists(FilePath)) 26 | { 27 | var text = File.ReadAllText(FilePath); 28 | (FacebookApi as FacebookApi).LoadStateDataFromString(text); 29 | } 30 | } 31 | 32 | /// 33 | /// Save current StateData from InstaApi 34 | /// 35 | public void Save() 36 | { 37 | File.WriteAllText(FilePath, (FacebookApi as FacebookApi).GetStateDataAsString()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/SessionHandlers/ISessionHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | 9 | namespace FacebookApiSharp.Classes.SessionHandlers 10 | { 11 | public interface ISessionHandler 12 | { 13 | IFacebookApi FacebookApi { get; set; } 14 | /// 15 | /// Path to file 16 | /// 17 | string FilePath { get; set; } 18 | 19 | /// 20 | /// Load and Set StateData to InstaApi 21 | /// 22 | void Load(); 23 | 24 | /// 25 | /// Save current StateData from InstaApi 26 | /// 27 | void Save(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/StateData.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.DeviceInfo; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Net; 11 | namespace FacebookApiSharp.Classes 12 | { 13 | [Serializable] 14 | public class StateData 15 | { 16 | public AndroidDevice DeviceInfo { get; set; } 17 | public UserSessionData UserSession { get; set; } 18 | public bool IsAuthenticated { get; set; } 19 | public List RawCookies { get; set; } 20 | 21 | #region Locale 22 | 23 | public string SimCountry { get; set; } = "unknown"; 24 | public string NetworkCountry { get; set; } = "unknown"; 25 | public string ClientCountryCode { get; set; } = "unknown"; 26 | public string DeviceLocale { get; set; } 27 | public string AppLocale { get; set; } 28 | public string AcceptLanguage { get; set; } 29 | 30 | #endregion 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Classes/UserSessionData.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using System; 9 | 10 | namespace FacebookApiSharp.Classes 11 | { 12 | [Serializable] 13 | public class UserSessionData 14 | { 15 | public string User { get; set; } 16 | public string Password { get; set; } 17 | public string PublicKey { get; internal set; } = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFyLzE2a2hJWWh1eklwVUF6QWt2YwpXSk1uTll0WmJRZ2JpY0M3RmdOQkpEblZMeHowbG5HUjJWNHZzN2w1S0h1VjkvK3lFZm1qRGU0VGcvRm5sK0I4ClR6TGdPZ0hpWG1LbFpIL1Y5TCt3MGh0cmVjUGlKVTc0Sjh2cHNwUHJNN3hhdlJnN256U0ZYZTYvTUxVNUMrb2gKejdRNjFJeFFrWGtvK0JQNnQ2elBrd3lVbnE2Y0NPckkrcm8xR2ZxNTdUMFRUUVh4WGJreW5FZmZyd3I3VEtsZQp1dEpvdG9sc1BwOTBNNnJvSU9nRzZqdzZ1TWlWYnYxSnp1UmM4V2hJbXBid2FLQmZVd0VYbUF4VzI2OW4yYzUvCmovN1RtUlpVckYxdk5RSm9ESk9OSTI2d09FeWRlRFVtYmtuek00NmVkUzNldnAwM1FNMlJFK2xHMXloQUlmeWcKdVFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg=="; 18 | public string PublicKeyId { get; internal set; } = "181"; 19 | public string MachineId { get; set; } 20 | public FacebookLoginSession LoggedInUser { get; set; } 21 | public static UserSessionData Empty => new UserSessionData(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/FacebookInboxFriendsConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace FacebookApiSharp.Converters 14 | { 15 | class FacebookInboxFriendsConverter : IObjectConverter 16 | { 17 | public FacebookInboxFriendsResponse SourceObject { get; set; } 18 | 19 | public FacebookInboxFriends Convert() 20 | { 21 | if (SourceObject == null) throw new ArgumentNullException($"Source object"); 22 | var inboxFriends = new FacebookInboxFriends 23 | { 24 | SelfUserId = SourceObject.Data?.Viewer?.AccountUser?.Id, 25 | Count = SourceObject.Data?.Viewer?.AccountUser?.Friends?.Count ?? 0 26 | }; 27 | if (SourceObject.Data?.Viewer?.AccountUser?.Friends?.Nodes?.Length > 0) 28 | { 29 | foreach(var item in SourceObject.Data.Viewer.AccountUser.Friends.Nodes) 30 | { 31 | inboxFriends.Users.Add(new FacebookInboxFriendsUser 32 | { 33 | Id = item.Id, 34 | ShortName = item.ShortName, 35 | Name = item.Name, 36 | ProfilePicture = item.ProfilePicture?.Uri 37 | }); 38 | } 39 | } 40 | return inboxFriends; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/FacebookInboxTopFriendsConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace FacebookApiSharp.Converters 14 | { 15 | class FacebookInboxTopFriendsConverter : IObjectConverter 16 | { 17 | public FacebookInboxFriendsResponse SourceObject { get; set; } 18 | 19 | public FacebookInboxTopFriends Convert() 20 | { 21 | if (SourceObject == null) throw new ArgumentNullException($"Source object"); 22 | var inboxTopFriends = new FacebookInboxTopFriends 23 | { 24 | SelfUserId = SourceObject.Data?.Viewer?.AccountUser?.Id, 25 | Count = SourceObject.Data?.Viewer?.AccountUser?.Friends?.Count ?? 0 26 | }; 27 | if (SourceObject.Data?.Viewer?.AccountUser?.TopFriends?.Nodes?.Length > 0) 28 | { 29 | foreach (var item in SourceObject.Data.Viewer.AccountUser.TopFriends.Nodes) 30 | { 31 | inboxTopFriends.Users.Add(new FacebookInboxTopFriendsUser 32 | { 33 | Id = item.Id, 34 | ShortName = item.ShortName, 35 | Name = item.Name, 36 | ProfilePicture = item.ProfilePicture?.Uri, 37 | LastActiveMessagesStatusTime = item.LastActiveMessagesStatus?.Time, 38 | IsCurrentlyActive = item.LastActiveMessagesStatus?.IsCurrentlyActive 39 | }); 40 | } 41 | } 42 | if (SourceObject.Data?.Viewer?.AccountUser?.TopFriendsWithMessenger?.Nodes?.Length > 0) 43 | { 44 | foreach (var item in SourceObject.Data.Viewer.AccountUser.TopFriendsWithMessenger.Nodes) 45 | { 46 | inboxTopFriends.Users.Add(new FacebookInboxTopFriendsUser 47 | { 48 | Id = item.Id, 49 | ShortName = item.ShortName, 50 | Name = item.Name, 51 | ProfilePicture = item.ProfilePicture?.Uri, 52 | LastActiveMessagesStatusTime = item.LastActiveMessagesStatus?.Time, 53 | IsCurrentlyActive = item.LastActiveMessagesStatus?.IsCurrentlyActive 54 | }); 55 | } 56 | } 57 | return inboxTopFriends; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/FacebookLoginSessionConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace FacebookApiSharp.Converters 14 | { 15 | class FacebookLoginSessionConverter : IObjectConverter 16 | { 17 | public FacebookLoginSessionResponse SourceObject { get; set; } 18 | 19 | public FacebookLoginSession Convert() 20 | { 21 | if (SourceObject == null) throw new ArgumentNullException($"Source object"); 22 | var loginSession = new FacebookLoginSession 23 | { 24 | AccessToken = SourceObject.AccessToken, 25 | Secret = SourceObject.Secret, 26 | SessionKey = SourceObject.SessionKey, 27 | UserStorageKey = SourceObject.UserStorageKey, 28 | AnalyticsClaim = SourceObject.AnalyticsClaim, 29 | Confirmed = SourceObject.Confirmed, 30 | Identifier = SourceObject.Identifier, 31 | UId = SourceObject.UId, 32 | }; 33 | return loginSession; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/FacebookMessageConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace FacebookApiSharp.Converters 14 | { 15 | class FacebookMessageConverter : IObjectConverter 16 | { 17 | public FacebookMessageContainerResponse SourceObject { get; set; } 18 | 19 | public FacebookMessage Convert() 20 | { 21 | if (SourceObject == null) throw new ArgumentNullException($"Source object"); 22 | var ss = SourceObject.Data.MessagingInBlueSendMessage.Message; 23 | var message = new FacebookMessage 24 | { 25 | ClientMutationId = SourceObject.Data.MessagingInBlueSendMessage.ClientMutationId, 26 | Id = ss.Id, 27 | Snippet = ss.Snippet, 28 | StrongId = ss.StrongId, 29 | MessageSender = ss.MessageSender.MessagingActor, 30 | MessageId = ss.MessageId, 31 | OfflineThreadingId = ss.OfflineThreadingId, 32 | TagsList = ss.TagsList, 33 | Text = ss.Message.Text, 34 | TimestampPrecise = ss.TimestampPrecise, 35 | Typename = ss.Typename, 36 | UnsentTimestampPrecise = ss.UnsentTimestampPrecise 37 | }; 38 | return message; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/Friends/FacebookFriendsConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace FacebookApiSharp.Converters 14 | { 15 | class FacebookFriendsConverter : IObjectConverter> 16 | { 17 | public FacebookPaginationResultResponse SourceObject { get; set; } 18 | 19 | public FacebookFriends Convert() 20 | { 21 | if (SourceObject == null) throw new ArgumentNullException($"Source object"); 22 | var friends = new FacebookFriends 23 | { 24 | PageInfo = SourceObject.Data?.Viewer?.DynamicFriendingTab?.PageInfo, 25 | FriendRequestCount = SourceObject.Data?.Viewer?.DynamicFriendingTab?.FriendRequestCount ?? 0 26 | }; 27 | if (SourceObject.Data?.Viewer?.DynamicFriendingTab?.Edges?.Length > 0) 28 | { 29 | foreach (var item in SourceObject.Data.Viewer.DynamicFriendingTab.Edges) 30 | { 31 | if (item.Node?.User != null) 32 | { 33 | friends.Users.Add(item.Node.User); 34 | } 35 | } 36 | } 37 | return friends; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/IObjectConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | namespace FacebookApiSharp.Converters 8 | { 9 | public interface IObjectConverter 10 | { 11 | TT SourceObject { get; set; } 12 | T Convert(); 13 | } 14 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Converters/ObjectsConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.Classes.Models; 8 | using FacebookApiSharp.Classes.Responses; 9 | using System; 10 | 11 | namespace FacebookApiSharp.Converters 12 | { 13 | public class ObjectsConverter 14 | { 15 | private static readonly Lazy LazyInstance = 16 | new Lazy(() => new ObjectsConverter()); 17 | public static ObjectsConverter Instance => LazyInstance.Value; 18 | 19 | 20 | public IObjectConverter GetUserShortConverter( 21 | FacebookLoginSessionResponse response) 22 | { 23 | return new FacebookLoginSessionConverter { SourceObject = response }; 24 | } 25 | 26 | public IObjectConverter GetDirectMessageConverter( 27 | FacebookMessageContainerResponse response) 28 | { 29 | return new FacebookMessageConverter { SourceObject = response }; 30 | } 31 | 32 | public IObjectConverter GetDirectInboxFriendsConverter( 33 | FacebookInboxFriendsResponse response) 34 | { 35 | return new FacebookInboxFriendsConverter { SourceObject = response }; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Enums/FacebookLoginResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Enums 12 | { 13 | public enum FacebookLoginResult 14 | { 15 | Success, 16 | WrongUserOrPassword, 17 | Unknown, 18 | //OAuthException, 19 | UnExpectedError, 20 | RenewPwdEncKeyPkg, 21 | SMScodeRequired 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Enums/ResponseType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | namespace FacebookApiSharp.Classes 7 | { 8 | public enum ResponseType 9 | { 10 | Unknown = 0, 11 | /// 12 | /// Everything works fine 13 | /// 14 | OK = 1, 15 | WrongRequest = 2, 16 | UnExpectedResponse = 3, 17 | NetworkProblem = 4, 18 | InternalException = 5, 19 | CheckpointAccount = 6, 20 | OAuthException = 7, 21 | AccountBlocked = 8, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/FacebookApiSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net461;netcoreapp3.1;net5.0;net6.0 5 | True 6 | FacebookApiSharp 7 | FacebookApiSharp 8 | false 9 | false 10 | false 11 | false 12 | 9.0.0.0 13 | 9.0.0.0 14 | 9.0.0.0 15 | 16 | A Tiny Private Facebook API for .NET. 17 | Features: 18 | - Login with facebook using email/phone and password 19 | - Search users 20 | - Get friends 21 | - Get direct inbox friends 22 | - Get direct top friends 23 | - Send direct text 24 | - Make new post 25 | - Upload photo 26 | 27 | Ramtin Jokar 28 | 29 | https://github.com/ramtinak/FacebookApiSharp/ 30 | https://github.com/ramtinak/FacebookApiSharp/ 31 | 32 | Ramtin Jokar [ Ramtinak@live.com ] 33 | false 34 | C#, Facebook, Client, Sharp, FacebookApiSharp, Client, Api, media, video, album, photo 35 | en-US 36 | true 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | all 52 | runtime; build; native; contentfiles; analyzers; buildtransitive 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/CryptoHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Security.Cryptography; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Helpers 12 | { 13 | public static class CryptoHelper 14 | { 15 | 16 | public static string Base64Encode(this string plainText) 17 | { 18 | return Base64Encode(Encoding.UTF8.GetBytes(plainText)); 19 | } 20 | public static string Base64Encode(this byte[] plainTextBytes) 21 | { 22 | return Convert.ToBase64String(plainTextBytes); 23 | } 24 | public static string Base64Decode(this string base64EncodedData) 25 | { 26 | var base64EncodedBytes = Convert.FromBase64String(base64EncodedData); 27 | return Encoding.UTF8.GetString(base64EncodedBytes); 28 | } 29 | public static string CalculateMd5() => CalculateMd5(System.IO.Path.GetRandomFileName()); 30 | 31 | public static string CalculateMd5(this string message) 32 | { 33 | var encoding = Encoding.UTF8; 34 | 35 | using (var md5 = MD5.Create()) 36 | { 37 | var hashed = md5.ComputeHash(encoding.GetBytes(message)); 38 | var hash = BitConverter.ToString(hashed).Replace("-", "").ToLower(); 39 | return hash; 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/DateTimeHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | 9 | namespace FacebookApiSharp.Helpers 10 | { 11 | public static class DateTimeHelper 12 | { 13 | private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 14 | 15 | public static DateTime FromUnixTimeSeconds(this long unixTime) 16 | { 17 | try 18 | { 19 | return UnixEpoch.AddSeconds(unixTime); 20 | } 21 | catch 22 | { 23 | return DateTime.MinValue; 24 | } 25 | } 26 | 27 | public static long ToUnixTime(this DateTime date) 28 | { 29 | try 30 | { 31 | return Convert.ToInt64((date - UnixEpoch).TotalSeconds); 32 | } 33 | catch 34 | { 35 | return 0; 36 | } 37 | } 38 | 39 | public static double ToUnixTimeAsDouble(this DateTime date) 40 | { 41 | try 42 | { 43 | return (date - UnixEpoch).TotalSeconds; 44 | } 45 | catch 46 | { 47 | return 0; 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/ExtensionsHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using FacebookApiSharp.Classes.DeviceInfo; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | using System.Linq; 13 | 14 | using Org.BouncyCastle.Security; 15 | using Org.BouncyCastle.Crypto.Modes; 16 | using Org.BouncyCastle.Crypto.Engines; 17 | using Org.BouncyCastle.Crypto.Parameters; 18 | using System.Net.Http.Headers; 19 | 20 | namespace FacebookApiSharp.Helpers 21 | { 22 | public static class ExtensionsHelper 23 | { 24 | readonly static Random Rnd = new Random(); 25 | public static string GetNewGuid() => 26 | Guid.NewGuid().ToString().Replace("-", ""); 27 | public static string GetGuid(this int length) => 28 | GetNewGuid().Substring(0, length); 29 | public static string GenerateUserAgent(this AndroidDevice deviceInfo, 30 | IFacebookApi facebookApi, 31 | bool userAgentGenTwo = false, 32 | string language = null) 33 | { 34 | var lang = language ?? facebookApi.AppLocale ?? "en_US"; 35 | var device = deviceInfo; 36 | var dpi = int.Parse(device.Dpi.Replace("dpi", "")); 37 | var res = device.Resolution.Split('x'); 38 | var width = res[0]; 39 | var height = res[1]; 40 | //[FBAN/FB4A;FBAV/355.0.0.21.108;FBBV/352948159;FBDM/{density=2.75,width=1080,height=2111};FBLC/en_US;FBRV/0;FBCR/IR-MCI;FBMF/Xiaomi;FBBD/Redmi;FBPN/com.facebook.katana;FBDV/M2007J22G;FBSV/11;FBBK/1;FBOP/1;FBCA/arm64-v8a:;] 41 | 42 | var fields = new Dictionary 43 | { 44 | {"FBAN", "FB4A"}, 45 | {"FBAV", FacebookApiConstants.FACEBOOK_API_VERSION}, 46 | {"FBBV", FacebookApiConstants.FACEBOOK_APP_VERSION}, 47 | {"FBDM", 48 | $"{{density={Math.Round(dpi/ 160f, 1):F1},width={width},height={height}}}" 49 | }, 50 | {"FBLC", lang.Replace("-","_")}, // en_US 51 | {"FBRV", "0"}, 52 | {"FBCR", ""}, // We don't have cellular // IR-MCI 53 | {"FBMF", device.HardwareManufacturer}, 54 | {"FBBD", device.AndroidBoardName}, 55 | {"FBPN", "com.facebook.katana"}, 56 | {"FBDV", device.HardwareModel}, 57 | {"FBSV", device.AndroidVer.VersionNumber}, 58 | {"FBBK", "1"}, 59 | {"FBOP", "1"}, 60 | {"FBCA", AndroidDevice.CPU_ABI} 61 | }; 62 | var mergeList = new List(); 63 | foreach (var field in fields) 64 | { 65 | mergeList.Add($"{field.Key}/{field.Value}"); 66 | } 67 | 68 | var userAgent = ""; 69 | foreach (var field in mergeList) 70 | { 71 | userAgent += field + ';'; 72 | } 73 | //Dalvik/2.1.0 (Linux; U; Android 11; M2007J22G Build/RP1A.200720.011) 74 | var generated = '[' + userAgent + ']'; 75 | if (userAgentGenTwo) 76 | { 77 | var ua = $"Dalvik/2.1.0 (Linux; U; {deviceInfo.AndroidVer.Codename}; " + 78 | $"{device.HardwareModel} Build/{device.HardwareModel}.{device.Resolution.Replace("x","")}.0) " + 79 | generated; 80 | 81 | return ua; 82 | } 83 | return generated; 84 | } 85 | public static string GenerateSnNonce(string emailOrPhoneNumber) 86 | { 87 | byte[] b = new byte[24]; 88 | Rnd.NextBytes(b); 89 | var str = $"{emailOrPhoneNumber}|{DateTimeHelper.ToUnixTime(DateTime.UtcNow)}|{Encoding.UTF8.GetString(b)}"; 90 | return Convert.ToBase64String(Encoding.UTF8.GetBytes(str)); 91 | } 92 | public static string GenerateJazoest(string phoneid) 93 | { 94 | int ix = 0; 95 | var chars = phoneid.ToCharArray(); 96 | foreach (var ch in chars) 97 | ix += (int)ch; 98 | return "2" + ix; 99 | } 100 | 101 | static private readonly SecureRandom secureRandom = new SecureRandom(); 102 | 103 | public static string GetEncryptedPassword(this IFacebookApi api, 104 | string password, long? providedTime = null) 105 | { 106 | var pubKey = api.GetLoggedUser().PublicKey; 107 | var pubKeyId = api.GetLoggedUser().PublicKeyId; 108 | byte[] randKey = new byte[32]; 109 | byte[] iv = new byte[12]; 110 | secureRandom.NextBytes(randKey, 0, randKey.Length); 111 | secureRandom.NextBytes(iv, 0, iv.Length); 112 | long time = providedTime ?? DateTime.UtcNow.ToUnixTime(); 113 | byte[] associatedData = Encoding.UTF8.GetBytes(time.ToString()); 114 | var pubKEY = pubKey.Base64Decode(); 115 | byte[] encryptedKey; 116 | using (var rdr = PemKeyUtils.GetRSAProviderFromPemString(pubKEY.Trim())) 117 | encryptedKey = rdr.Encrypt(randKey, false); 118 | 119 | byte[] plaintext = Encoding.UTF8.GetBytes(password); 120 | 121 | var cipher = new GcmBlockCipher(new AesEngine()); 122 | var parameters = new AeadParameters(new KeyParameter(randKey), 128, iv, associatedData); 123 | cipher.Init(true, parameters); 124 | 125 | var ciphertext = new byte[cipher.GetOutputSize(plaintext.Length)]; 126 | var len = cipher.ProcessBytes(plaintext, 0, plaintext.Length, ciphertext, 0); 127 | cipher.DoFinal(ciphertext, len); 128 | 129 | var con = new byte[plaintext.Length]; 130 | for (int i = 0; i < plaintext.Length; i++) 131 | con[i] = ciphertext[i]; 132 | ciphertext = con; 133 | var tag = cipher.GetMac(); 134 | 135 | byte[] buffersSize = BitConverter.GetBytes(Convert.ToInt16(encryptedKey.Length)); 136 | byte[] encKeyIdBytes = BitConverter.GetBytes(Convert.ToUInt16(pubKeyId)); 137 | if (BitConverter.IsLittleEndian) 138 | Array.Reverse(encKeyIdBytes); 139 | encKeyIdBytes[0] = 1; 140 | var payload = encKeyIdBytes 141 | .Concat(iv) 142 | .Concat(buffersSize) 143 | .Concat(encryptedKey) 144 | .Concat(tag) 145 | .Concat(ciphertext) 146 | .ToArray() 147 | .Base64Encode(); 148 | 149 | return $"#PWD_FB4A:2:{time}:{payload}"; 150 | } 151 | public static string GetThreadToken() 152 | { 153 | //6906811681774978189 154 | var str = ""; 155 | str += Rnd.Next(1, 9); 156 | str += Rnd.Next(1, 9); 157 | str += Rnd.Next(1, 9); 158 | str += Rnd.Next(2, 9); 159 | str += Rnd.Next(1000, 9999); 160 | str += Rnd.Next(11111, 99999); 161 | 162 | str += Rnd.Next(2222, 6789); 163 | 164 | return $"92{str}"; 165 | } 166 | public static (bool, string) CheckpointCheck(HttpHeaders headers) 167 | { 168 | if ((headers?.Contains("x-fb-integrity-required") ?? false) && 169 | (headers?.Contains("nt") ?? false)) 170 | { 171 | //x-fb-integrity-enrollment:["UVZSUGFXNUNlVXcxYTFKbWRDMVpXbGN0TFZoa2JVcHJOelpwVUdGTmFXRnVNVGRVU3pSUk1uUk1aMnh1VGxKNk5EUmxYelF0TkRoYVpEbDJaVlZhWjAxa05YTktMVk5pZWw5bWQxUnpXR2hUUzNwemNYcGZSakYwT0d0NlMwZzVUV3RKZDFCU1ozb3lSekpoYmpGc1JVSldNbU0wTUZseVowTkNWRFp3YW14SmJXRkhkVlJRUmsxRWNVUTBiRUZuWVhRNGFqQXlObkkxVDJKMFMySkdZelJ1WmkxVlJHOTNUVmcyVERjM1dGOTZRVkoxUm14YWJUUm9SVnBmUW1aTVFsRndXWFZFT0ZocWNtWldMVFpFWjIxeGQwWnJVWEJzUWpsb04xRm5PSFZmZG1SdGNUWjFSa3RhTlhabVpWQktha2xpVFVneVlXZGlOVVpuWVdKWWFYbFFXVVJOVjNJNVNXNWFkbDh3U1V4Q1RHYzJjRXhFTVhGUGFEVlJPRUZwZVdNeFYxSmpkak5OU21KalVERkJjWEJOZFVGeVh6RmZVbWhaYkZoVlRYZEtOVFJHVVROUVNFc3laMlpEYW5CTlRUQlJXa3RvZDFFMlYyVjVjbmN5TjFOdVQwZHJUMTluVUdKRExVUmZVVVJLTm01SGRFeFFkMGRtV2s5VU9HZEhiVWxmWDA5VmFuZDViVzFxWVRKVWR6VnVRM2s1VVRZeGRWbE9OemRtVFVkUFNsWlBjRVJJVlVOUWRFcGxaR1puTm01aWRGQnNaM2xuYXpKRVJHbHFiM0pvTTBvMmNtWjA="] 172 | //x-fb-integrity-session-id:["754ed23d-9600-4687-8120-0001b617887a"] 173 | //x-fb-integrity-required:["checkpoint"] 174 | //x-fb-integrity-render-mode:["nt"] 175 | return (true, "Your account got locked by Facebook.\nYou can unlock it via Facebook application and verify that you aren't a bot"); 176 | } 177 | else 178 | return (false, "OK"); 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Style", "IDE1006:Naming Styles")] 9 | [assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter")] 10 | [assembly: SuppressMessage("Style", "IDE0051:Private member")] 11 | [assembly: SuppressMessage("Style", "CS0612")] 12 | [assembly: SuppressMessage("Style", "CS0618")] 13 | [assembly: SuppressMessage("Style", "CA1507")] 14 | [assembly: SuppressMessage("Style", "CA2211")] 15 | [assembly: SuppressMessage("Style", "XAML0618")] 16 | [assembly: SuppressMessage("Style", "IDE0618")] 17 | [assembly: SuppressMessage("Style", "IDE0034")] 18 | [assembly: SuppressMessage("Style", "CS0067")] 19 | [assembly: SuppressMessage("Style", "C4244")] 20 | [assembly: SuppressMessage("Style", "C4267")] 21 | [assembly: SuppressMessage("Style", "IDE0018")] 22 | [assembly: SuppressMessage("Style", "IDE0019")] 23 | [assembly: SuppressMessage("Style", "IDE0044")] 24 | [assembly: SuppressMessage("Style", "IDE0051")] 25 | [assembly: SuppressMessage("Style", "IDE0052")] 26 | [assembly: SuppressMessage("Style", "IDE0054")] 27 | [assembly: SuppressMessage("Style", "IDE0057")] 28 | [assembly: SuppressMessage("Style", "IDE0063")] 29 | [assembly: SuppressMessage("Style", "IDE0066")] 30 | [assembly: SuppressMessage("Style", "IDE0079")] 31 | [assembly: SuppressMessage("Style", "IDE0083:Use pattern matching")] 32 | [assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization")] 33 | [assembly: SuppressMessage("Style", "IDE0090:Use 'new(...)'")] 34 | [assembly: SuppressMessage("Style", "IDE0074:Use compound assignment")] 35 | [assembly: SuppressMessage("Style", "IDE0017:Simplify object initialization")] 36 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/HttpExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using System; 9 | using System.Net.Http.Headers; 10 | 11 | namespace FacebookApiSharp.Helpers 12 | { 13 | public static class HttpExtensions 14 | { 15 | public static Uri AddQueryParameter(this Uri uri, string name, string value, bool dontCheck = false) 16 | { 17 | if (!dontCheck) 18 | if (value == null || value == "" || value == "[]") return uri; 19 | 20 | if (value == null) 21 | value = ""; 22 | var httpValueCollection = HttpUtility.ParseQueryString(uri); 23 | 24 | httpValueCollection.Remove(name); 25 | httpValueCollection.Add(name, value); 26 | 27 | var ub = new UriBuilder(uri); 28 | var q = ""; 29 | foreach (var item in httpValueCollection) 30 | { 31 | if (q == "") q += $"{item.Key}={item.Value}"; 32 | else q += $"&{item.Key}={item.Value}"; 33 | } 34 | ub.Query = q; 35 | return ub.Uri; 36 | } 37 | internal static void AddHeader(this HttpRequestHeaders headers, 38 | string name, 39 | string value, 40 | bool removeHeader = false) 41 | { 42 | var currentCulture = HttpHelper.GetCurrentCulture(); 43 | System.Globalization.CultureInfo.CurrentCulture = HttpHelper.EnglishCulture; 44 | 45 | if (removeHeader) 46 | headers.Remove(name); 47 | 48 | headers.Add(name, value); 49 | 50 | System.Globalization.CultureInfo.CurrentCulture = currentCulture; 51 | } 52 | internal static void AddHeader(this HttpContentHeaders headers, string name, 53 | string value, 54 | bool removeHeader = false) 55 | { 56 | var currentCulture = HttpHelper.GetCurrentCulture(); 57 | System.Globalization.CultureInfo.CurrentCulture = HttpHelper.EnglishCulture; 58 | 59 | if (removeHeader) 60 | headers.Remove(name); 61 | 62 | headers.Add(name, value); 63 | 64 | System.Globalization.CultureInfo.CurrentCulture = currentCulture; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/HttpHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using FacebookApiSharp.Classes; 9 | using FacebookApiSharp.Classes.DeviceInfo; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Net.Http; 13 | 14 | namespace FacebookApiSharp.Helpers 15 | { 16 | public class HttpHelper 17 | { 18 | public IHttpRequestProcessor _httpRequestProcessor; 19 | public IFacebookApi _facebookApi; 20 | internal HttpHelper(IHttpRequestProcessor httpRequestProcessor, IFacebookApi facebookApi) 21 | { 22 | _httpRequestProcessor = httpRequestProcessor; 23 | _facebookApi = facebookApi; 24 | } 25 | 26 | internal static readonly System.Globalization.CultureInfo EnglishCulture = new System.Globalization.CultureInfo("en-us"); 27 | internal static System.Globalization.CultureInfo GetCurrentCulture() => System.Globalization.CultureInfo.CurrentCulture; 28 | 29 | public HttpRequestMessage GetDefaultRequest(HttpMethod method, 30 | Uri uri, 31 | AndroidDevice deviceInfo, 32 | bool userAgentGenTwo = false) 33 | { 34 | var currentCulture = GetCurrentCulture(); 35 | System.Globalization.CultureInfo.CurrentCulture = EnglishCulture; 36 | var userAgent = deviceInfo.GenerateUserAgent(_facebookApi, userAgentGenTwo); 37 | var currentUser = _facebookApi.GetLoggedUser(); 38 | var request = new HttpRequestMessage(method, uri); 39 | 40 | //X-FB-Connection-Quality: EXCELLENT 41 | //X-FB-SIM-HNI: 43235 42 | //X-FB-Net-HNI: 43211 43 | //X-FB-Connection-Type: unknown 44 | //User-Agent: [FBAN/FB4A;FBAV/355.0.0.21.108;FBBV/352948159;FBDM/{density=2.75,width=1080,height=2111};FBLC/en_US;FBRV/0;FBCR/IR-MCI;FBMF/Xiaomi;FBBD/Redmi;FBPN/com.facebook.katana;FBDV/M2007J22G;FBSV/11;FBBK/1;FBOP/1;FBCA/arm64-v8a:;] 45 | //Host: graph.facebook.com 46 | //Content-Type: application/x-www-form-urlencoded 47 | //X-Tigon-Is-Retry: False 48 | //x-fb-device-group: 7864 49 | //X-FB-Friendly-Name: suggestedLanguages 50 | //X-FB-Request-Analytics-Tags: unknown 51 | //Accept-Encoding: gzip, deflate 52 | //X-FB-HTTP-Engine: Liger 53 | //X-FB-Client-IP: True 54 | //X-FB-Server-Cluster: True 55 | 56 | request.Headers.Add(FacebookApiConstants.HEADER_FB_CONNECTION_QUALITY, "EXCELLENT"); 57 | request.Headers.Add(FacebookApiConstants.HEADER_FB_SIM_HNI, "unknown"); 58 | request.Headers.Add(FacebookApiConstants.HEADER_FB_NET_HNI, "unknown"); 59 | request.Headers.Add(FacebookApiConstants.HEADER_FB_CONNECTION_TYPE, "WIFI"); 60 | // Authorization: OAuth 61 | if(IsLoggedIn() && !string.IsNullOrEmpty(currentUser.LoggedInUser.AccessToken)) 62 | { 63 | request.Headers.Add(FacebookApiConstants.HEADER_AUTHORIZATION, $"OAuth {currentUser.LoggedInUser.AccessToken}"); 64 | } 65 | request.Headers.TryAddWithoutValidation(FacebookApiConstants.HEADER_USER_AGENT, userAgent); 66 | request.Headers.Add(FacebookApiConstants.HEADER_FB_DEVICE_GROUP, "7864"); 67 | request.Headers.Add(FacebookApiConstants.HEADER_FB_FRIENDLY_NAME, "suggestedLanguages"); 68 | request.Headers.Add(FacebookApiConstants.HEADER_FB_REQUEST_ANALYTICS_TAGS, "unknown"); 69 | request.Headers.Add(FacebookApiConstants.HEADER_FB_HTTP_ENGINE, "Liger"); 70 | request.Headers.Add(FacebookApiConstants.HEADER_FB_SERVER_CLUSTER, "True"); 71 | request.Headers.Add(FacebookApiConstants.HEADER_X_IG_TIGON_RETRY, "False"); 72 | 73 | 74 | request.Headers.Add(FacebookApiConstants.HEADER_ACCEPT_LANGUAGE, _facebookApi.AcceptLanguage); 75 | 76 | request.Headers.TryAddWithoutValidation(FacebookApiConstants.HEADER_ACCEPT_ENCODING, FacebookApiConstants.ACCEPT_ENCODING2); 77 | 78 | //request.Headers.Add(FacebookApiConstants.HOST, FacebookApiConstants.HOST_URI); 79 | 80 | System.Globalization.CultureInfo.CurrentCulture = currentCulture; 81 | 82 | bool IsLoggedIn() 83 | { 84 | return _facebookApi.IsUserAuthenticated && currentUser.LoggedInUser != null; 85 | } 86 | 87 | return request; 88 | } 89 | public HttpRequestMessage GetDefaultRequest(HttpMethod method, 90 | Uri uri, AndroidDevice deviceInfo, 91 | Dictionary data, 92 | bool userAgentGenTwo = false) 93 | { 94 | var request = GetDefaultRequest(HttpMethod.Post, uri, deviceInfo, userAgentGenTwo); 95 | request.Content = new FormUrlEncodedContent(data); 96 | return request; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/HttpUtility.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | 11 | namespace FacebookApiSharp.Helpers 12 | { 13 | public class HttpUtility 14 | { 15 | public static Dictionary ParseQueryString(Uri uri) 16 | { 17 | if (uri == null) 18 | throw new ArgumentNullException("uri"); 19 | 20 | if (uri.Query.Length == 0) 21 | return new Dictionary(); 22 | 23 | return uri.Query.TrimStart('?') 24 | .Split(new[] { '&', ';' }, StringSplitOptions.RemoveEmptyEntries) 25 | .Select(parameter => parameter.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries)) 26 | .GroupBy(parts => parts[0], 27 | parts => parts.Length > 2 ? string.Join("=", parts, 1, parts.Length - 1) : (parts.Length > 1 ? parts[1] : "")) 28 | .ToDictionary(grouping => grouping.Key, 29 | grouping => string.Join(",", grouping)); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/SerializationHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System.IO; 9 | using System.Text; 10 | 11 | namespace FacebookApiSharp.Helpers 12 | { 13 | internal class SerializationHelper 14 | { 15 | public static Stream SerializeToStream(object o) 16 | { 17 | var json = SerializeToString(o); 18 | var bytes = Encoding.UTF8.GetBytes(json); 19 | var stream = new MemoryStream(bytes); 20 | return stream; 21 | } 22 | 23 | public static T DeserializeFromStream(Stream stream) 24 | { 25 | var json = new StreamReader(stream).ReadToEnd(); 26 | return DeserializeFromString(json); 27 | } 28 | public static string SerializeToString(object o) 29 | { 30 | return JsonConvert.SerializeObject(o); 31 | } 32 | 33 | public static T DeserializeFromString(string json) 34 | { 35 | return JsonConvert.DeserializeObject(json); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/FacebookApiSharp/Helpers/UriCreator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using FacebookApiSharp.API; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace FacebookApiSharp.Helpers 13 | { 14 | public class UriCreator 15 | { 16 | private static readonly Uri FacebookUri = new Uri(FacebookApiConstants.FACEBOOK_URL); 17 | private static readonly Uri BFacebookUri = new Uri(FacebookApiConstants.B_FACEBOOK_URL); 18 | 19 | 20 | public static Uri GetAppLocaleSuggestionsUri() 21 | { 22 | if (!Uri.TryCreate(FacebookUri, 23 | "/app/locale_suggestions", 24 | out var instaUri)) 25 | throw new Exception("Cant create URI GetAppLocaleSuggestionsUri"); 26 | return instaUri; 27 | } 28 | public static Uri GetZeroHeadersPingParamsUri() 29 | { 30 | if (!Uri.TryCreate(BFacebookUri, 31 | "/zero_headers_ping_params_v2?fields=use_for_fos,use_for_login,clear,remove_keys,next_cursor,cooldown_on_success,cooldown_on_failure,uri,transparency_content,transparency_content_type,carrier_name,carrier_id,consent_required,transparency_design,client_header_params,headwind_program,headwind_storage,headwind_immediate,user_signal_required", 32 | out var instaUri)) 33 | throw new Exception("Cant create URI GetZeroHeadersPingParamsUri"); 34 | return instaUri; 35 | } 36 | public static Uri GetMobileGatekeepersUri() 37 | { 38 | if (!Uri.TryCreate(BFacebookUri, 39 | "/mobile_gatekeepers", 40 | out var instaUri)) 41 | throw new Exception("Cant create URI GetMobileGateKeepersUri"); 42 | return instaUri; 43 | } 44 | public static Uri GetLoggingClientEventsUri() 45 | { 46 | if (!Uri.TryCreate(FacebookUri, 47 | "/logging_client_events", 48 | out var instaUri)) 49 | throw new Exception("Cant create URI GetLoggingClientEventsUri"); 50 | return instaUri; 51 | } 52 | 53 | public static Uri GetAuthLoginUri() 54 | { 55 | if (!Uri.TryCreate(BFacebookUri, 56 | "/auth/login", 57 | out var instaUri)) 58 | throw new Exception("Cant create URI GetAuthLoginUri"); 59 | return instaUri; 60 | } 61 | 62 | public static Uri GetGraphQLUri() 63 | { 64 | if (!Uri.TryCreate(FacebookUri, 65 | "/graphql", 66 | out var instaUri)) 67 | throw new Exception("Cant create URI GetGraphQLUri"); 68 | return instaUri; 69 | } 70 | 71 | public static Uri GetNetworkInterfaceUri() 72 | { 73 | if (!Uri.TryCreate(FacebookUri, 74 | "/v3.2/cdn_rmd?net_iface=Wifi&reason=APP_START", 75 | out var instaUri)) 76 | throw new Exception("Cant create URI GetNetworkInterfaceUri"); 77 | return instaUri; 78 | } 79 | 80 | public static Uri GetPersistentComponentsUri(string locale, string clientCountryCode) 81 | { 82 | if (!Uri.TryCreate(BFacebookUri, 83 | $"/?include_headers=false&decode_body_json=false&streamable_json_response=true&locale={locale}&client_country_code={clientCountryCode}", 84 | out var instaUri)) 85 | throw new Exception("Cant create URI GetPersistentComponentsUri"); 86 | return instaUri; 87 | } 88 | 89 | public static Uri GetLoginApprovalsKeysUri() 90 | { 91 | if (!Uri.TryCreate(FacebookUri, 92 | "/100034137818552/loginapprovalskeys", // yeah its two slashes! 93 | out var instaUri)) 94 | throw new Exception("Cant create URI GetLoginApprovalsKeysUri"); 95 | return instaUri; 96 | } 97 | 98 | public static Uri GetPasswordEncrytionKeyUri() 99 | { 100 | if (!Uri.TryCreate(FacebookUri, 101 | "/pwd_key_fetch", // yeah its two slashes! 102 | out var instaUri)) 103 | throw new Exception("Cant create URI GetPasswordEncrytionKeyUri"); 104 | return instaUri; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ramtin Jokar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Logger/DebugLogger.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Net; 13 | using System.Net.Http; 14 | using System.Net.Http.Headers; 15 | using System.Text; 16 | using System.Threading.Tasks; 17 | 18 | namespace FacebookApiSharp.Logger 19 | { 20 | public class DebugLogger : IFacebookLogger 21 | { 22 | public string UserName { get; set; } 23 | public string LetsLog { get; set; } 24 | private readonly LogLevel _logLevel; 25 | 26 | public DebugLogger(LogLevel loglevel) 27 | { 28 | _logLevel = loglevel; 29 | } 30 | public DebugLogger(LogLevel loglevel, string userName = "noName", string logStuff = "true") 31 | { 32 | LetsLog = logStuff; 33 | UserName = userName; 34 | _logLevel = loglevel; 35 | } 36 | 37 | public async Task LogRequest(HttpRequestMessage request) 38 | { 39 | if (_logLevel < LogLevel.Request) return; 40 | WriteSeprator(); 41 | Write($"Request: {request.Method} {request.RequestUri}"); 42 | WriteHeaders(request.Headers); 43 | #if NET 44 | WriteProperties(request.Options); 45 | #else 46 | WriteProperties(request.Properties); 47 | #endif 48 | if (request.Method == HttpMethod.Post) 49 | await WriteRequestContent(request.Content); 50 | } 51 | 52 | public void LogRequest(Uri uri) 53 | { 54 | if (_logLevel < LogLevel.Request) return; 55 | Write($"Request: {uri}"); 56 | } 57 | 58 | public async Task LogResponse(HttpResponseMessage response) 59 | { 60 | if (_logLevel < LogLevel.Response) return; 61 | Write($"Response: {response.RequestMessage.Method} {response.RequestMessage.RequestUri} [{response.StatusCode}]"); 62 | WriteHeaders(response.Headers); 63 | await WriteContent(response.Content, Formatting.None, 0); 64 | } 65 | 66 | public void LogException(Exception ex) 67 | { 68 | if (_logLevel < LogLevel.Exceptions) return; 69 | #if NETSTANDARD || NET || NETCOREAPP3_1 70 | Console.WriteLine($"Exception: {ex}"); 71 | Console.WriteLine($"Stacktrace: {ex.StackTrace}"); 72 | #else 73 | System.Diagnostics.Debug.WriteLine($"Exception: {ex}"); 74 | System.Diagnostics.Debug.WriteLine($"Stacktrace: {ex.StackTrace}"); 75 | #endif 76 | } 77 | 78 | public void LogInfo(string info) 79 | { 80 | if (_logLevel < LogLevel.Info) return; 81 | Write($"Info:{Environment.NewLine}{info}"); 82 | } 83 | 84 | private void WriteHeaders(HttpHeaders headers) 85 | { 86 | if (headers == null) return; 87 | if (!headers.Any()) return; 88 | Write("Headers:"); 89 | foreach (var item in headers) 90 | Write($"{item.Key}:{JsonConvert.SerializeObject(item.Value)}"); 91 | } 92 | 93 | private void WriteProperties(IDictionary properties) 94 | { 95 | if (properties == null) return; 96 | if (properties.Count == 0) return; 97 | Write($"Properties:\n{JsonConvert.SerializeObject(properties, Formatting.Indented)}"); 98 | } 99 | 100 | private async Task WriteContent(HttpContent content, Formatting formatting, int maxLength = 0) 101 | { 102 | Write("Content:"); 103 | if (content.Headers.ContentType != null) 104 | content.Headers.ContentType.CharSet = "utf-8"; 105 | var raw = await content.ReadAsStringAsync(); 106 | if (formatting == Formatting.Indented) raw = FormatJson(raw); 107 | raw = raw.Contains("") ? "got html content!" : raw; 108 | if ((raw.Length > maxLength) & (maxLength != 0)) 109 | raw = raw.Substring(0, maxLength); 110 | Write(raw); 111 | } 112 | private async Task WriteRequestContent(HttpContent content, int maxLength = 0) 113 | { 114 | Write("Content:"); 115 | if(content == null) 116 | { 117 | Write("Doesn't have any content"); 118 | return; 119 | } 120 | var raw = await content.ReadAsStringAsync(); 121 | if ((raw.Length > maxLength) & (maxLength != 0)) 122 | raw = raw.Substring(0, maxLength); 123 | Write(WebUtility.UrlDecode(raw)); 124 | } 125 | 126 | private void WriteSeprator() 127 | { 128 | var sep = new StringBuilder(); 129 | for (var i = 0; i < 100; i++) sep.Append("-"); 130 | Write(sep.ToString()); 131 | } 132 | 133 | private string FormatJson(string json) 134 | { 135 | dynamic parsedJson = JsonConvert.DeserializeObject(json); 136 | return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); 137 | } 138 | 139 | private void Write(string message) 140 | { 141 | if (LetsLog == "true") 142 | { 143 | Directory.CreateDirectory("debug"); 144 | File.AppendAllText($@"debug\{UserName}.txt", $"{DateTime.Now.ToString()}:\t{message}" + Environment.NewLine); 145 | } 146 | #if NETSTANDARD || NET || NETCOREAPP3_1 147 | Console.WriteLine($"{DateTime.Now}:\t{message}"); 148 | #else 149 | System.Diagnostics.Debug.WriteLine($"{DateTime.Now}:\t{message}"); 150 | #endif 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Logger/FileDebugLogger.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using Newtonsoft.Json; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Net; 13 | using System.Net.Http; 14 | using System.Net.Http.Headers; 15 | using System.Text; 16 | using System.Threading.Tasks; 17 | 18 | namespace FacebookApiSharp.Logger 19 | { 20 | public class FileDebugLogger : IFacebookLogger 21 | { 22 | private readonly string FilePath; 23 | private readonly LogLevel _logLevel; 24 | private readonly object _lock = new object(); 25 | 26 | public FileDebugLogger(LogLevel loglevel, string fileName = null) 27 | { 28 | _logLevel = loglevel; 29 | 30 | if (string.IsNullOrEmpty(fileName)) 31 | fileName = $"logs {DateTime.Now:MM-dd-yy H-mm-ss}.txt"; 32 | 33 | FilePath = fileName; 34 | } 35 | public async Task LogRequest(HttpRequestMessage request) 36 | { 37 | if (_logLevel < LogLevel.Request) return; 38 | var sb = new StringBuilder(); 39 | var headers = WriteHeaders(request.Headers); 40 | string properties; 41 | sb.AppendLine(WriteSeprator()); 42 | sb.AppendLine(GetText($"Request: {request.Method} {request.RequestUri}")); 43 | if (!string.IsNullOrEmpty(headers)) 44 | sb.Append(headers); 45 | #if NET 46 | properties = WriteProperties(request.Options); 47 | #else 48 | properties = WriteProperties(request.Properties); 49 | #endif 50 | if (!string.IsNullOrEmpty(properties)) 51 | sb.AppendLine(properties); 52 | if (request.Method == HttpMethod.Post) 53 | sb.AppendLine(await WriteRequestContent(request.Content)); 54 | Write(sb.ToString().TrimStart()); 55 | } 56 | 57 | public void LogRequest(Uri uri) 58 | { 59 | if (_logLevel < LogLevel.Request) return; 60 | Write(GetText($"Request: {uri}")); 61 | } 62 | 63 | public async Task LogResponse(HttpResponseMessage response) 64 | { 65 | if (_logLevel < LogLevel.Response) return; 66 | var sb = new StringBuilder(); 67 | var headers = WriteHeaders(response.Headers); 68 | sb.AppendLine(GetText($"Response: {response.RequestMessage.Method} {response.RequestMessage.RequestUri} [{response.StatusCode}]")); 69 | if (!string.IsNullOrEmpty(headers)) 70 | sb.AppendLine(headers); 71 | sb.Append(await WriteContent(response.Content, Formatting.None, 0)); 72 | Write(sb.ToString()); 73 | } 74 | 75 | public void LogException(Exception ex) 76 | { 77 | if (_logLevel < LogLevel.Exceptions) return; 78 | 79 | string text = $"Exception: {ex}" + 80 | Environment.NewLine + 81 | $"Stacktrace: {ex.StackTrace}"; 82 | 83 | Write(GetText(text)); 84 | } 85 | 86 | public void LogInfo(string info) 87 | { 88 | if (_logLevel < LogLevel.Info) return; 89 | Write(GetText($"Info:{Environment.NewLine}{info}")); 90 | } 91 | 92 | private string WriteHeaders(HttpHeaders headers) 93 | { 94 | if (headers == null) return null; 95 | if (!headers.Any()) return null; 96 | var sb = new StringBuilder(); 97 | sb.AppendLine(GetText("Headers:")); 98 | foreach (var item in headers) 99 | sb.AppendLine(GetText($"{item.Key}:{JsonConvert.SerializeObject(item.Value)}")); 100 | 101 | return sb.ToString(); 102 | } 103 | 104 | private string WriteProperties(IDictionary properties) 105 | { 106 | if (properties == null) return null; 107 | if (properties.Count == 0) return null; 108 | return GetText($"Properties:\n{JsonConvert.SerializeObject(properties, Formatting.Indented)}"); 109 | } 110 | 111 | private async Task WriteContent(HttpContent content, Formatting formatting, int maxLength = 0) 112 | { 113 | var sb = new StringBuilder(); 114 | sb.Append(GetText("Content:")); 115 | if (content == null) 116 | { 117 | sb.Append(GetText("Doesn't have any content")); 118 | return sb.ToString(); 119 | } 120 | var raw = await content.ReadAsStringAsync(); 121 | if (formatting == Formatting.Indented) raw = FormatJson(raw); 122 | raw = raw.Contains("") ? "got html content!" : raw; 123 | if ((raw.Length > maxLength) & (maxLength != 0)) 124 | raw = raw.Substring(0, maxLength); 125 | sb.AppendLine(GetText(raw)); 126 | return sb.ToString(); 127 | } 128 | 129 | private async Task WriteRequestContent(HttpContent content, int maxLength = 0) 130 | { 131 | var sb = new StringBuilder(); 132 | sb.Append(GetText("Content:")); 133 | if (content == null) 134 | { 135 | sb.Append(GetText("Doesn't have any content")); 136 | return sb.ToString(); 137 | } 138 | var raw = await content.ReadAsStringAsync(); 139 | if ((raw.Length > maxLength) & (maxLength != 0)) 140 | raw = raw.Substring(0, maxLength); 141 | sb.AppendLine(GetText(WebUtility.UrlDecode(raw))); 142 | return sb.ToString(); 143 | } 144 | 145 | private string WriteSeprator() 146 | { 147 | var sep = new StringBuilder(); 148 | for (var i = 0; i < 100; i++) sep.Append("-"); 149 | return GetText(sep.ToString()); 150 | } 151 | 152 | private string FormatJson(string json) 153 | { 154 | dynamic parsedJson = JsonConvert.DeserializeObject(json); 155 | return JsonConvert.SerializeObject(parsedJson, Formatting.Indented); 156 | } 157 | 158 | private void Write(string message) 159 | { 160 | lock (_lock) 161 | { 162 | File.AppendAllText(FilePath, message); 163 | } 164 | } 165 | 166 | private string GetText(string message) 167 | { 168 | return $"{DateTime.Now}:\t{message}"; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Logger/IFacebookLogger.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | using System; 8 | using System.Net.Http; 9 | using System.Threading.Tasks; 10 | 11 | namespace FacebookApiSharp.Logger 12 | { 13 | public interface IFacebookLogger 14 | { 15 | Task LogRequest(HttpRequestMessage request); 16 | void LogRequest(Uri uri); 17 | Task LogResponse(HttpResponseMessage response); 18 | void LogException(Exception exception); 19 | void LogInfo(string info); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/FacebookApiSharp/Logger/LogLevel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Developer: Ramtin Jokar [ Ramtinak@live.com ] [ License: MIT ] 3 | * 4 | * 2022 - Dedicated Library 5 | */ 6 | 7 | namespace FacebookApiSharp.Logger 8 | { 9 | public enum LogLevel 10 | { 11 | None = 0, 12 | Exceptions = 1, 13 | Info = 2, 14 | Request = 3, 15 | Response = 4, 16 | All = 5 17 | } 18 | } 19 | --------------------------------------------------------------------------------