Skip to content

Instantly share code, notes, and snippets.

@Dainius14
Last active October 17, 2022 21:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Dainius14/92d188859b0aa87918ddda266e85db91 to your computer and use it in GitHub Desktop.
Gets Facebook access token for use in Tinder application.
using SimpleBrowser;
using System.Threading;
static class FbHelper
{
private static readonly string URL = @"https://www.facebook.com/v2.6/dialog/oauth?redirect_uri=fb464891386855067%3A%2F%2Fauthorize%2F&scope=user_birthday,user_photos,user_education_history,email,user_relationship_details,user_friends,user_work_history,user_likes&response_type=token%2Csigned_request&client_id=464891386855067";
private static readonly string USER_AGENT = "Mozilla/5.0 (Linux; U; en-gb; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.16 Safari/535.19";
public static string GetFbToken(string email, string password)
{
string token = string.Empty;
Browser browser = new Browser();
browser.UserAgent = USER_AGENT;
browser.Navigate(URL);
// Enters email, password and logins
browser.Find(ElementType.TextField, FindBy.Name, "email").Value = email;
browser.Find("u_0_2").Value = password;
browser.Find(ElementType.Button, FindBy.Name, "login").Click();
// If SMS authentication is enabled, after aprooving from the browser manually, clicks ok to continue
while (browser.ContainsText("Enter Security Code to Continue"))
{
browser.Navigate(browser.Url);
Thread.Sleep(1000);
}
// Tinder is already authorized prompt, presses ok
browser.Find("u_0_1").Click();
// access_token= lenght is 13
int indexOfTokenEnd = browser.CurrentHtml.IndexOf("access_token=") + 13;
token = browser.CurrentHtml.Remove(0, indexOfTokenEnd);
token = token.Remove(token.IndexOf("&"));
return token;
}
}
@Dainius14
Copy link
Author

Requires SimpleBrowser

Usage: Simply pass email and password to the method and it returns your freshly baked token.

Improtant:

If SMS two factor authentication is enabled, you need to manually accept new browser through your browser, where you're logged in.
In the meantime while you're doing that, the method simply pauses the thread and hangs the whole application. :) Advanced engineering right there.
Just what I need right now, better than getting the code manually.

@warzbird
Copy link

Any help on getting this to run on VS? I installed SimpeBrowser via Package manager, but when paste the FB token code in a form, it has errors. Any suggestions?

@warzbird
Copy link

image

Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Thread' does not exist in the current context ClassLibrary1 c:\users\pc\documents\visual studio 2015\Projects\ClassLibrary1\ClassLibrary1\Class1.cs 25 Active

@Dainius14
Copy link
Author

Woops sorry. You also need to import System.Threading;
using System.Threading;

Next time, just put your marker on the area underlined by that marker and press Ctrl+. It will show needed corrections automatically.

@romeosr
Copy link

romeosr commented Aug 2, 2017

how to run it bro

@joynal5696
Copy link

uyh

@joynal5696
Copy link

ttt76

@romeosr
Copy link

romeosr commented Oct 5, 2017

how to run this bro???

@fritz-net
Copy link

It's not working anymore, it seams they changed the link to something like this https://m.facebook.com/v2.7/dialog/oauth....

@Colosmican
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment