Link to home
Start Free TrialLog in
Avatar of JoachimPetersen
JoachimPetersenFlag for Denmark

asked on

Problems implementing Tinder API in vb .net

Hello

I am just trying to toy around with the Tinder API, I've found the following link describing the tinder API:
https://gist.github.com/rtt/10403467

When I try the Authenticating function, I get a 403 Forbidden Error with the following vb.net code:
Dim wHeader As WebHeaderCollection = New WebHeaderCollection()

        wHeader.Clear()
        'wHeader.Add("Content-type: application/json")
        'wHeader.Add("User-agent: User-Agent: Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)")
        wHeader.Add("facebook_token: ####")
        wHeader.Add("facebook_id: 1391287###")

        Dim sUrl As String = "https://api.gotinder.com/auth"

        Dim wRequest As HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(sUrl), HttpWebRequest)

        wRequest.ContentType = "application/json"
        wRequest.UserAgent = "Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)"
        wRequest.Headers = wHeader
        wRequest.Method = "GET"
        Try
            Dim wResponse As HttpWebResponse = DirectCast(wRequest.GetResponse(), HttpWebResponse)
            Dim sResponse As String = ""
            Using srRead As New StreamReader(wResponse.GetResponseStream())
                sResponse = srRead.ReadToEnd()
            End Using
            MsgBox(sResponse)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Open in new window

You can get your facebook token from here:
https://www.facebook.com/dialog/oauth?client_id=464891386855067&redirect_uri=https://www.facebook.com/connect/login_success.html&scope=basic_info,email,public_profile,user_about_me,user_activities,user_birthday,user_education_history,user_friends,user_interests,user_likes,user_location,user_photos,user_relationship_details&response_type=token
and you can find your facebook id with the following website:
http://findmyfacebookid.com/

What am I doing wrong, is the API changed or am I doing something wrong in my .net code?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't have any experience with the Tinder API, so I will need to figure out how the OAuth piece works. If you are passing Facebook ID and Facebook token, and hitting the correct URL (api.gotinder.com/auth), then it sounds like it is going to be more challenging.
A few of the reasons that I don't like Tinder:

A brilliant Tinder hack made hundreds of bros unwittingly flirt with each other
http://www.theverge.com/2015/3/25/8277743/tinder-hack-bros-swiping-bros
Avatar of JoachimPetersen

ASKER

Well, granted that any API can be misused, there is also a lot more potential in a constructive perspective.
I think I'll just have to sniff the app and see if the API has changed, as far as I can understand, my .net code is not the source of the error.
I see where you are using the version in the user agent:

wRequest.UserAgent = "Tinder/3.0.4 (iPhone; iOS 7.1; Scale/2.00)"

I also see that there is a 4.0.4 version.
Found out that the API has changed, ALOT (sniffed out the data and found the new parameters) , but the problem I am facing now is that when I try to set an header, ie: Content-Type, I get the following error: "The Content-Type header cannot be changed from its default value for this request.", any idea how I cound fix this, as this is an actual 'code' question
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy(); //To sign the SS to avoid error
      
            string URL = "https://api.gotinder.com/auth";
            WebClient webClient = new WebClient();
            //webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
            //webClient.Headers["Content-Type"] = "application/json";
            //webClient.Headers.Set("Content-Type", "application/json");
            //When I try to change the content-type at this point, I end up with this error "The Content-Type header cannot be changed from its default value for this request."
            webClient.Headers[HttpRequestHeader.UserAgent] = "Tinder Android Version 4.1.6";
            System.Collections.Specialized.NameValueCollection formData = new System.Collections.Specialized.NameValueCollection();
            formData["facebook_token"] = "***Facebook Token***";
            formData["locale"] = "da";
            byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
            string Result = Encoding.UTF8.GetString(responseBytes);

            textBox1.Text = Result;

Open in new window

Here is the MyPolicy to sign the SSL to avoid any SSL errors:
using System.Security.Cryptography.X509Certificates;
using System.Net;

public class MyPolicy : ICertificatePolicy
{
    public bool CheckValidationResult(ServicePoint srvPoint,
      X509Certificate certificate, WebRequest request,
      int certificateProblem)
    {
        //Return True to force the certificate to be accepted.
        return true;
    }
}

Open in new window

You can't set Content-type with UploadValues, you  would need to use UploadData instead.
ASKER CERTIFIED SOLUTION
Avatar of JoachimPetersen
JoachimPetersen
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
figured it out myself